
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pymatgen.io.abinit.pseudos &#8212; pymatgen 2020.7.3 documentation</title>
    <link rel="stylesheet" href="../../../../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
    <script src="../../../../_static/jquery.js"></script>
    <script src="../../../../_static/underscore.js"></script>
    <script src="../../../../_static/doctools.js"></script>
    <script src="../../../../_static/language_data.js"></script>
    <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../search.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33990148-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../pymatgen.html" accesskey="U">pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.io.abinit.pseudos</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <h1>Source code for pymatgen.io.abinit.pseudos</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding: utf-8</span>
<span class="c1"># Copyright (c) Pymatgen Development Team.</span>
<span class="c1"># Distributed under the terms of the MIT License.</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">This module provides objects describing the basic parameters of the</span>
<span class="sd">pseudopotentials used in Abinit, and a parser to instantiate pseudopotential objects..</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">abc</span>
<span class="kn">import</span> <span class="nn">collections</span>
<span class="kn">import</span> <span class="nn">json</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">collections</span> <span class="kn">import</span> <span class="n">OrderedDict</span><span class="p">,</span> <span class="n">defaultdict</span><span class="p">,</span> <span class="n">namedtuple</span>
<span class="kn">from</span> <span class="nn">monty.collections</span> <span class="kn">import</span> <span class="n">AttrDict</span><span class="p">,</span> <span class="n">Namespace</span>
<span class="kn">from</span> <span class="nn">tabulate</span> <span class="kn">import</span> <span class="n">tabulate</span>
<span class="c1"># from monty.dev import deprecated</span>
<span class="kn">from</span> <span class="nn">monty.functools</span> <span class="kn">import</span> <span class="n">lazy_property</span>
<span class="kn">from</span> <span class="nn">monty.itertools</span> <span class="kn">import</span> <span class="n">iterator_from_slice</span>
<span class="kn">from</span> <span class="nn">monty.json</span> <span class="kn">import</span> <span class="n">MSONable</span><span class="p">,</span> <span class="n">MontyDecoder</span>
<span class="kn">from</span> <span class="nn">monty.os.path</span> <span class="kn">import</span> <span class="n">find_exts</span>
<span class="kn">from</span> <span class="nn">monty.string</span> <span class="kn">import</span> <span class="n">list_strings</span><span class="p">,</span> <span class="n">is_string</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.periodic_table</span> <span class="kn">import</span> <span class="n">Element</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.xcfunc</span> <span class="kn">import</span> <span class="n">XcFunc</span>
<span class="kn">from</span> <span class="nn">pymatgen.util.serialization</span> <span class="kn">import</span> <span class="n">pmg_serialize</span>
<span class="kn">from</span> <span class="nn">pymatgen.util.plotting</span> <span class="kn">import</span> <span class="n">add_fig_kwargs</span><span class="p">,</span> <span class="n">get_ax_fig_plt</span>

<span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span>

<span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span>
    <span class="s2">&quot;Pseudo&quot;</span><span class="p">,</span>
    <span class="s2">&quot;PseudoTable&quot;</span><span class="p">,</span>
<span class="p">]</span>

<span class="n">__author__</span> <span class="o">=</span> <span class="s2">&quot;Matteo Giantomassi&quot;</span>
<span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;0.1&quot;</span>
<span class="n">__maintainer__</span> <span class="o">=</span> <span class="s2">&quot;Matteo Giantomassi&quot;</span>


<span class="c1"># Tools and helper functions.</span>

<span class="k">def</span> <span class="nf">straceback</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;Returns a string with the traceback.&quot;&quot;&quot;</span>
    <span class="kn">import</span> <span class="nn">traceback</span>
    <span class="k">return</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">((</span><span class="n">traceback</span><span class="o">.</span><span class="n">format_exc</span><span class="p">(),</span> <span class="nb">str</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">exc_info</span><span class="p">()[</span><span class="mi">0</span><span class="p">])))</span>


<span class="k">def</span> <span class="nf">_read_nlines</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">nlines</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Read at most nlines lines from file filename.</span>
<span class="sd">    If nlines is &lt; 0, the entire file is read.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">nlines</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;r&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fh</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">fh</span><span class="o">.</span><span class="n">readlines</span><span class="p">()</span>

    <span class="n">lines</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;r&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fh</span><span class="p">:</span>
        <span class="k">for</span> <span class="n">lineno</span><span class="p">,</span> <span class="n">line</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">fh</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">lineno</span> <span class="o">==</span> <span class="n">nlines</span><span class="p">:</span>
                <span class="k">break</span>
            <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">lines</span>


<span class="n">_l2str</span> <span class="o">=</span> <span class="p">{</span>
    <span class="mi">0</span><span class="p">:</span> <span class="s2">&quot;s&quot;</span><span class="p">,</span>
    <span class="mi">1</span><span class="p">:</span> <span class="s2">&quot;p&quot;</span><span class="p">,</span>
    <span class="mi">2</span><span class="p">:</span> <span class="s2">&quot;d&quot;</span><span class="p">,</span>
    <span class="mi">3</span><span class="p">:</span> <span class="s2">&quot;f&quot;</span><span class="p">,</span>
    <span class="mi">4</span><span class="p">:</span> <span class="s2">&quot;g&quot;</span><span class="p">,</span>
    <span class="mi">5</span><span class="p">:</span> <span class="s2">&quot;h&quot;</span><span class="p">,</span>
    <span class="mi">6</span><span class="p">:</span> <span class="s2">&quot;i&quot;</span><span class="p">,</span>
<span class="p">}</span>

<span class="n">_str2l</span> <span class="o">=</span> <span class="p">{</span><span class="n">v</span><span class="p">:</span> <span class="n">k</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">_l2str</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>


<span class="k">def</span> <span class="nf">l2str</span><span class="p">(</span><span class="n">l</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Convert the angular momentum l (int) to string.&quot;&quot;&quot;</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">_l2str</span><span class="p">[</span><span class="n">l</span><span class="p">]</span>
    <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
        <span class="k">return</span> <span class="s2">&quot;Unknown angular momentum, received l = </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">l</span>


<span class="k">def</span> <span class="nf">str2l</span><span class="p">(</span><span class="n">s</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Convert a string to the angular momentum l (int)&quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="n">_str2l</span><span class="p">[</span><span class="n">s</span><span class="p">]</span>


<div class="viewcode-block" id="Pseudo"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.Pseudo">[docs]</a><span class="k">class</span> <span class="nc">Pseudo</span><span class="p">(</span><span class="n">MSONable</span><span class="p">,</span> <span class="n">metaclass</span><span class="o">=</span><span class="n">abc</span><span class="o">.</span><span class="n">ABCMeta</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Abstract base class defining the methods that must be</span>
<span class="sd">    implemented by the concrete pseudopotential sub-classes.</span>
<span class="sd">    &quot;&quot;&quot;</span>

<div class="viewcode-block" id="Pseudo.as_pseudo"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.Pseudo.as_pseudo">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">as_pseudo</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">obj</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Convert obj into a pseudo. Accepts:</span>

<span class="sd">            * Pseudo object.</span>
<span class="sd">            * string defining a valid path.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">obj</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="bp">cls</span><span class="p">)</span> <span class="k">else</span> <span class="bp">cls</span><span class="o">.</span><span class="n">from_file</span><span class="p">(</span><span class="n">obj</span><span class="p">)</span></div>

<div class="viewcode-block" id="Pseudo.from_file"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.Pseudo.from_file">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">from_file</span><span class="p">(</span><span class="n">filename</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Build an instance of a concrete Pseudo subclass from filename.</span>
<span class="sd">        Note: the parser knows the concrete class that should be instantiated</span>
<span class="sd">        Client code should rely on the abstract interface provided by Pseudo.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">PseudoParser</span><span class="p">()</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span></div>

    <span class="k">def</span> <span class="fm">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">other</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>
        <span class="k">return</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">md5</span> <span class="o">==</span> <span class="n">other</span><span class="o">.</span><span class="n">md5</span> <span class="ow">and</span>
                <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span> <span class="o">==</span> <span class="n">other</span><span class="o">.</span><span class="vm">__class__</span> <span class="ow">and</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">Z</span> <span class="o">==</span> <span class="n">other</span><span class="o">.</span><span class="n">Z</span> <span class="ow">and</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">Z_val</span> <span class="o">==</span> <span class="n">other</span><span class="o">.</span><span class="n">Z_val</span> <span class="ow">and</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">l_max</span> <span class="o">==</span> <span class="n">other</span><span class="o">.</span><span class="n">l_max</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__ne__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">return</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="fm">__eq__</span><span class="p">(</span><span class="n">other</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">return</span> <span class="s2">&quot;&lt;</span><span class="si">%s</span><span class="s2"> at </span><span class="si">%s</span><span class="s2">&gt;&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">relpath</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filepath</span><span class="p">))</span>
        <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
            <span class="c1"># relpath can fail if the code is executed in demon mode.</span>
            <span class="k">return</span> <span class="s2">&quot;&lt;</span><span class="si">%s</span><span class="s2"> at </span><span class="si">%s</span><span class="s2">&gt;&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">filepath</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">to_string</span><span class="p">()</span>

<div class="viewcode-block" id="Pseudo.to_string"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.Pseudo.to_string">[docs]</a>    <span class="k">def</span> <span class="nf">to_string</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">verbose</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;String representation.&quot;&quot;&quot;</span>
        <span class="n">lines</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">app</span> <span class="o">=</span> <span class="n">lines</span><span class="o">.</span><span class="n">append</span>
        <span class="n">app</span><span class="p">(</span><span class="s2">&quot;&lt;</span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">&gt;&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">basename</span><span class="p">))</span>
        <span class="n">app</span><span class="p">(</span><span class="s2">&quot;  summary: &quot;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">summary</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span>
        <span class="n">app</span><span class="p">(</span><span class="s2">&quot;  number of valence electrons: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">Z_val</span><span class="p">)</span>
        <span class="n">app</span><span class="p">(</span><span class="s2">&quot;  maximum angular momentum: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">l2str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">l_max</span><span class="p">))</span>
        <span class="n">app</span><span class="p">(</span><span class="s2">&quot;  angular momentum for local part: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">l2str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">l_local</span><span class="p">))</span>
        <span class="n">app</span><span class="p">(</span><span class="s2">&quot;  XC correlation: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">xc</span><span class="p">)</span>
        <span class="n">app</span><span class="p">(</span><span class="s2">&quot;  supports spin-orbit: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">supports_soc</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">isnc</span><span class="p">:</span>
            <span class="n">app</span><span class="p">(</span><span class="s2">&quot;  radius for non-linear core correction: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">nlcc_radius</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_hints</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">accuracy</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">&quot;low&quot;</span><span class="p">,</span> <span class="s2">&quot;normal&quot;</span><span class="p">,</span> <span class="s2">&quot;high&quot;</span><span class="p">):</span>
                <span class="n">hint</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">hint_for_accuracy</span><span class="p">(</span><span class="n">accuracy</span><span class="o">=</span><span class="n">accuracy</span><span class="p">)</span>
                <span class="n">app</span><span class="p">(</span><span class="s2">&quot;  hint for </span><span class="si">%s</span><span class="s2"> accuracy: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">accuracy</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">hint</span><span class="p">)))</span>

        <span class="k">return</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">lines</span><span class="p">)</span></div>

    <span class="nd">@property</span>
    <span class="nd">@abc</span><span class="o">.</span><span class="n">abstractmethod</span>
    <span class="k">def</span> <span class="nf">summary</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;String summarizing the most important properties.&quot;&quot;&quot;</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">filepath</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Absolute path to pseudopotential file.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">path</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">basename</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;File basename.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">basename</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filepath</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="nd">@abc</span><span class="o">.</span><span class="n">abstractmethod</span>
    <span class="k">def</span> <span class="nf">Z</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;The atomic number of the atom.&quot;&quot;&quot;</span>

    <span class="nd">@property</span>
    <span class="nd">@abc</span><span class="o">.</span><span class="n">abstractmethod</span>
    <span class="k">def</span> <span class="nf">Z_val</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Valence charge.&quot;&quot;&quot;</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">type</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Type of pseudo.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">element</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Pymatgen :class:`Element`.&quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">Element</span><span class="o">.</span><span class="n">from_Z</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">Z</span><span class="p">)</span>
        <span class="k">except</span> <span class="p">(</span><span class="ne">KeyError</span><span class="p">,</span> <span class="ne">IndexError</span><span class="p">):</span>
            <span class="k">return</span> <span class="n">Element</span><span class="o">.</span><span class="n">from_Z</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">Z</span><span class="p">))</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">symbol</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Element symbol.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">element</span><span class="o">.</span><span class="n">symbol</span>

    <span class="nd">@property</span>
    <span class="nd">@abc</span><span class="o">.</span><span class="n">abstractmethod</span>
    <span class="k">def</span> <span class="nf">l_max</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Maximum angular momentum.&quot;&quot;&quot;</span>

    <span class="nd">@property</span>
    <span class="nd">@abc</span><span class="o">.</span><span class="n">abstractmethod</span>
    <span class="k">def</span> <span class="nf">l_local</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Angular momentum used for the local part.&quot;&quot;&quot;</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">isnc</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;True if norm-conserving pseudopotential.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">NcPseudo</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">ispaw</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;True if PAW pseudopotential.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">PawPseudo</span><span class="p">)</span>

<div class="viewcode-block" id="Pseudo.md5"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.Pseudo.md5">[docs]</a>    <span class="nd">@lazy_property</span>
    <span class="k">def</span> <span class="nf">md5</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;MD5 hash value.&quot;&quot;&quot;</span>
        <span class="c1"># if self.has_dojo_report and &quot;md5&quot; in self.dojo_report: return self.dojo_report[&quot;md5&quot;]</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">compute_md5</span><span class="p">()</span></div>

<div class="viewcode-block" id="Pseudo.compute_md5"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.Pseudo.compute_md5">[docs]</a>    <span class="k">def</span> <span class="nf">compute_md5</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Compute and erturn MD5 hash value.&quot;&quot;&quot;</span>
        <span class="kn">import</span> <span class="nn">hashlib</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">path</span><span class="p">,</span> <span class="s2">&quot;rt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fh</span><span class="p">:</span>
            <span class="n">text</span> <span class="o">=</span> <span class="n">fh</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
            <span class="n">m</span> <span class="o">=</span> <span class="n">hashlib</span><span class="o">.</span><span class="n">md5</span><span class="p">(</span><span class="n">text</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">&quot;utf-8&quot;</span><span class="p">))</span>
            <span class="k">return</span> <span class="n">m</span><span class="o">.</span><span class="n">hexdigest</span><span class="p">()</span></div>

    <span class="nd">@property</span>
    <span class="nd">@abc</span><span class="o">.</span><span class="n">abstractmethod</span>
    <span class="k">def</span> <span class="nf">supports_soc</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        True if the pseudo can be used in a calculation with spin-orbit coupling.</span>
<span class="sd">        Base classes should provide a concrete implementation that computes this value.</span>
<span class="sd">        &quot;&quot;&quot;</span>

<div class="viewcode-block" id="Pseudo.as_dict"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.Pseudo.as_dict">[docs]</a>    <span class="nd">@pmg_serialize</span>
    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return dictionary for MSONable protocol.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">dict</span><span class="p">(</span>
            <span class="n">basename</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">basename</span><span class="p">,</span>
            <span class="nb">type</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">type</span><span class="p">,</span>
            <span class="n">symbol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">symbol</span><span class="p">,</span>
            <span class="n">Z</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">Z</span><span class="p">,</span>
            <span class="n">Z_val</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">Z_val</span><span class="p">,</span>
            <span class="n">l_max</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">l_max</span><span class="p">,</span>
            <span class="n">md5</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">md5</span><span class="p">,</span>
            <span class="n">filepath</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">filepath</span><span class="p">,</span>
            <span class="c1"># xc=self.xc.as_dict(),</span>
        <span class="p">)</span></div>

<div class="viewcode-block" id="Pseudo.from_dict"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.Pseudo.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Build instance from dictionary (MSONable protocol).&quot;&quot;&quot;</span>
        <span class="n">new</span> <span class="o">=</span> <span class="bp">cls</span><span class="o">.</span><span class="n">from_file</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;filepath&#39;</span><span class="p">])</span>

        <span class="c1"># Consistency test based on md5</span>
        <span class="k">if</span> <span class="s2">&quot;md5&quot;</span> <span class="ow">in</span> <span class="n">d</span> <span class="ow">and</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;md5&quot;</span><span class="p">]</span> <span class="o">!=</span> <span class="n">new</span><span class="o">.</span><span class="n">md5</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;The md5 found in file does not agree with the one in dict</span><span class="se">\n</span><span class="s2">&quot;</span>
                             <span class="s2">&quot;Received </span><span class="si">%s</span><span class="se">\n</span><span class="s2">Computed </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;md5&quot;</span><span class="p">],</span> <span class="n">new</span><span class="o">.</span><span class="n">md5</span><span class="p">))</span>

        <span class="k">return</span> <span class="n">new</span></div>

<div class="viewcode-block" id="Pseudo.as_tmpfile"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.Pseudo.as_tmpfile">[docs]</a>    <span class="k">def</span> <span class="nf">as_tmpfile</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tmpdir</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Copy the pseudopotential to a temporary a file and returns a new pseudopotential object.</span>
<span class="sd">        Useful for unit tests in which we have to change the content of the file.</span>

<span class="sd">        Args:</span>
<span class="sd">            tmpdir: If None, a new temporary directory is created and files are copied here</span>
<span class="sd">                else tmpdir is used.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="kn">import</span> <span class="nn">tempfile</span>
        <span class="kn">import</span> <span class="nn">shutil</span>
        <span class="n">tmpdir</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mkdtemp</span><span class="p">()</span> <span class="k">if</span> <span class="n">tmpdir</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="n">tmpdir</span>
        <span class="n">new_path</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">tmpdir</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">basename</span><span class="p">)</span>
        <span class="n">shutil</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filepath</span><span class="p">,</span> <span class="n">new_path</span><span class="p">)</span>

        <span class="c1"># Copy dojoreport file if present.</span>
        <span class="n">root</span><span class="p">,</span> <span class="n">ext</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">splitext</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filepath</span><span class="p">)</span>
        <span class="n">djrepo</span> <span class="o">=</span> <span class="n">root</span> <span class="o">+</span> <span class="s2">&quot;.djrepo&quot;</span>
        <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">djrepo</span><span class="p">):</span>
            <span class="n">shutil</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">djrepo</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">tmpdir</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">basename</span><span class="p">(</span><span class="n">djrepo</span><span class="p">)))</span>

        <span class="c1"># Build new object and copy dojo_report if present.</span>
        <span class="n">new</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="n">from_file</span><span class="p">(</span><span class="n">new_path</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_dojo_report</span><span class="p">:</span>
            <span class="n">new</span><span class="o">.</span><span class="n">dojo_report</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dojo_report</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">()</span>

        <span class="k">return</span> <span class="n">new</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">has_dojo_report</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;True if the pseudo has an associated `DOJO_REPORT` section.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s2">&quot;dojo_report&quot;</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">bool</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dojo_report</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">djrepo_path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;The path of the djrepo file. None if file does not exist.&quot;&quot;&quot;</span>
        <span class="n">root</span><span class="p">,</span> <span class="n">ext</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">splitext</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filepath</span><span class="p">)</span>
        <span class="n">path</span> <span class="o">=</span> <span class="n">root</span> <span class="o">+</span> <span class="s2">&quot;.djrepo&quot;</span>
        <span class="k">return</span> <span class="n">path</span>
        <span class="c1"># if os.path.exists(path): return path</span>
        <span class="c1"># return None</span>

<div class="viewcode-block" id="Pseudo.hint_for_accuracy"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.Pseudo.hint_for_accuracy">[docs]</a>    <span class="k">def</span> <span class="nf">hint_for_accuracy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">accuracy</span><span class="o">=</span><span class="s2">&quot;normal&quot;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns a :class:`Hint` object with the suggested value of ecut [Ha] and</span>
<span class="sd">        pawecutdg [Ha] for the given accuracy.</span>
<span class="sd">        ecut and pawecutdg are set to zero if no hint is available.</span>

<span class="sd">        Args:</span>
<span class="sd">            accuracy: [&quot;low&quot;, &quot;normal&quot;, &quot;high&quot;]</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_dojo_report</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">Hint</span><span class="p">(</span><span class="n">ecut</span><span class="o">=</span><span class="mf">0.</span><span class="p">,</span> <span class="n">pawecutdg</span><span class="o">=</span><span class="mf">0.</span><span class="p">)</span>

        <span class="c1"># Get hints from dojoreport. Try first in hints then in ppgen_hints.</span>
        <span class="k">if</span> <span class="s2">&quot;hints&quot;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dojo_report</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">Hint</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dojo_report</span><span class="p">[</span><span class="s2">&quot;hints&quot;</span><span class="p">][</span><span class="n">accuracy</span><span class="p">])</span>
        <span class="k">elif</span> <span class="s2">&quot;ppgen_hints&quot;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dojo_report</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">Hint</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dojo_report</span><span class="p">[</span><span class="s2">&quot;ppgen_hints&quot;</span><span class="p">][</span><span class="n">accuracy</span><span class="p">])</span>
        <span class="k">return</span> <span class="n">Hint</span><span class="p">(</span><span class="n">ecut</span><span class="o">=</span><span class="mf">0.</span><span class="p">,</span> <span class="n">pawecutdg</span><span class="o">=</span><span class="mf">0.</span><span class="p">)</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">has_hints</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        True if self provides hints on the cutoff energy.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">acc</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;low&quot;</span><span class="p">,</span> <span class="s2">&quot;normal&quot;</span><span class="p">,</span> <span class="s2">&quot;high&quot;</span><span class="p">]:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">hint_for_accuracy</span><span class="p">(</span><span class="n">acc</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="k">return</span> <span class="kc">False</span>
            <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
                <span class="k">return</span> <span class="kc">False</span>
        <span class="k">return</span> <span class="kc">True</span>

<div class="viewcode-block" id="Pseudo.open_pspsfile"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.Pseudo.open_pspsfile">[docs]</a>    <span class="k">def</span> <span class="nf">open_pspsfile</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ecut</span><span class="o">=</span><span class="mi">20</span><span class="p">,</span> <span class="n">pawecutdg</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Calls Abinit to compute the internal tables for the application of the</span>
<span class="sd">        pseudopotential part. Returns :class:`PspsFile` object providing methods</span>
<span class="sd">        to plot and analyze the data or None if file is not found or it&#39;s not readable.</span>

<span class="sd">        Args:</span>
<span class="sd">            ecut: Cutoff energy in Hartree.</span>
<span class="sd">            pawecutdg: Cutoff energy for the PAW double grid.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="kn">from</span> <span class="nn">abipy.flowtk</span> <span class="kn">import</span> <span class="n">AbinitTask</span>
        <span class="kn">from</span> <span class="nn">abipy.core.structure</span> <span class="kn">import</span> <span class="n">Structure</span>
        <span class="kn">from</span> <span class="nn">abipy.abio.factories</span> <span class="kn">import</span> <span class="n">gs_input</span>
        <span class="kn">from</span> <span class="nn">abipy.electrons.psps</span> <span class="kn">import</span> <span class="n">PspsFile</span>

        <span class="c1"># Build fake structure.</span>
        <span class="n">lattice</span> <span class="o">=</span> <span class="mi">10</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">eye</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
        <span class="n">structure</span> <span class="o">=</span> <span class="n">Structure</span><span class="p">(</span><span class="n">lattice</span><span class="p">,</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">element</span><span class="p">],</span> <span class="n">coords</span><span class="o">=</span><span class="p">[[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]])</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">ispaw</span> <span class="ow">and</span> <span class="n">pawecutdg</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">pawecutdg</span> <span class="o">=</span> <span class="n">ecut</span> <span class="o">*</span> <span class="mi">4</span>
        <span class="n">inp</span> <span class="o">=</span> <span class="n">gs_input</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">pseudos</span><span class="o">=</span><span class="p">[</span><span class="bp">self</span><span class="p">],</span> <span class="n">ecut</span><span class="o">=</span><span class="n">ecut</span><span class="p">,</span> <span class="n">pawecutdg</span><span class="o">=</span><span class="n">pawecutdg</span><span class="p">,</span>
                       <span class="n">spin_mode</span><span class="o">=</span><span class="s2">&quot;unpolarized&quot;</span><span class="p">,</span> <span class="n">kppa</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
        <span class="c1"># Add prtpsps = -1 to make Abinit print the PSPS.nc file and stop.</span>
        <span class="n">inp</span><span class="p">[</span><span class="s2">&quot;prtpsps&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>

        <span class="c1"># Build temporary task and run it (ignore retcode because we don&#39;t exit cleanly)</span>
        <span class="n">task</span> <span class="o">=</span> <span class="n">AbinitTask</span><span class="o">.</span><span class="n">temp_shell_task</span><span class="p">(</span><span class="n">inp</span><span class="p">)</span>
        <span class="n">task</span><span class="o">.</span><span class="n">start_and_wait</span><span class="p">()</span>

        <span class="n">filepath</span> <span class="o">=</span> <span class="n">task</span><span class="o">.</span><span class="n">outdir</span><span class="o">.</span><span class="n">has_abiext</span><span class="p">(</span><span class="s2">&quot;_PSPS.nc&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">filepath</span><span class="p">:</span>
            <span class="n">logger</span><span class="o">.</span><span class="n">critical</span><span class="p">(</span><span class="s2">&quot;Cannot find PSPS.nc file in </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">task</span><span class="o">.</span><span class="n">outdir</span><span class="p">)</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="c1"># Open the PSPS.nc file.</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">PspsFile</span><span class="p">(</span><span class="n">filepath</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">exc</span><span class="p">:</span>
            <span class="n">logger</span><span class="o">.</span><span class="n">critical</span><span class="p">(</span><span class="s2">&quot;Exception while reading PSPS file at </span><span class="si">%s</span><span class="s2">:</span><span class="se">\n</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">filepath</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">exc</span><span class="p">)))</span>
            <span class="k">return</span> <span class="kc">None</span></div></div>


<span class="k">class</span> <span class="nc">NcPseudo</span><span class="p">(</span><span class="n">metaclass</span><span class="o">=</span><span class="n">abc</span><span class="o">.</span><span class="n">ABCMeta</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Abstract class defining the methods that must be implemented</span>
<span class="sd">    by the concrete classes representing norm-conserving pseudopotentials.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="nd">@property</span>
    <span class="nd">@abc</span><span class="o">.</span><span class="n">abstractmethod</span>
    <span class="k">def</span> <span class="nf">nlcc_radius</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Radius at which the core charge vanish (i.e. cut-off in a.u.).</span>
<span class="sd">        Returns 0.0 if nlcc is not used.</span>
<span class="sd">        &quot;&quot;&quot;</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">has_nlcc</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;True if the pseudo is generated with non-linear core correction.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">nlcc_radius</span> <span class="o">&gt;</span> <span class="mf">0.0</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">rcore</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Radius of the pseudization sphere in a.u.&quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_core</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>


<span class="k">class</span> <span class="nc">PawPseudo</span><span class="p">(</span><span class="n">metaclass</span><span class="o">=</span><span class="n">abc</span><span class="o">.</span><span class="n">ABCMeta</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Abstract class that defines the methods that must be implemented</span>
<span class="sd">    by the concrete classes representing PAW pseudopotentials.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="c1"># def nlcc_radius(self):</span>
    <span class="c1">#    &quot;&quot;&quot;</span>
    <span class="c1">#    Radius at which the core charge vanish (i.e. cut-off in a.u.).</span>
    <span class="c1">#    Returns 0.0 if nlcc is not used.</span>
    <span class="c1">#    &quot;&quot;&quot;</span>
    <span class="c1">#    return 0.0</span>
    <span class="c1">#</span>

    <span class="c1"># @property</span>
    <span class="c1"># def has_nlcc(self):</span>
    <span class="c1">#    &quot;&quot;&quot;True if the pseudo is generated with non-linear core correction.&quot;&quot;&quot;</span>
    <span class="c1">#    return True</span>

    <span class="nd">@property</span>
    <span class="nd">@abc</span><span class="o">.</span><span class="n">abstractmethod</span>
    <span class="k">def</span> <span class="nf">paw_radius</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Radius of the PAW sphere in a.u.&quot;&quot;&quot;</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">rcore</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Alias of paw_radius.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">paw_radius</span>


<span class="k">class</span> <span class="nc">AbinitPseudo</span><span class="p">(</span><span class="n">Pseudo</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    An AbinitPseudo is a pseudopotential whose file contains an abinit header.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">header</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            path: Filename.</span>
<span class="sd">            header: :class:`AbinitHeader` instance.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">path</span> <span class="o">=</span> <span class="n">path</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">header</span> <span class="o">=</span> <span class="n">header</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_summary</span> <span class="o">=</span> <span class="n">header</span><span class="o">.</span><span class="n">summary</span>

        <span class="c1"># Build xc from header.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">xc</span> <span class="o">=</span> <span class="n">XcFunc</span><span class="o">.</span><span class="n">from_abinit_ixc</span><span class="p">(</span><span class="n">header</span><span class="p">[</span><span class="s2">&quot;pspxc&quot;</span><span class="p">])</span>

        <span class="k">for</span> <span class="n">attr_name</span><span class="p">,</span> <span class="n">desc</span> <span class="ow">in</span> <span class="n">header</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">value</span> <span class="o">=</span> <span class="n">header</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">attr_name</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

            <span class="c1"># Hide these attributes since one should always use the public interface.</span>
            <span class="nb">setattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s2">&quot;_&quot;</span> <span class="o">+</span> <span class="n">attr_name</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">summary</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Summary line reported in the ABINIT header.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_summary</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">Z</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_zatom</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">Z_val</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_zion</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">l_max</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_lmax</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">l_local</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_lloc</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">supports_soc</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="c1"># Treate ONCVPSP pseudos</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pspcod</span> <span class="o">==</span> <span class="mi">8</span><span class="p">:</span>
            <span class="n">switch</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">header</span><span class="p">[</span><span class="s2">&quot;extension_switch&quot;</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">switch</span> <span class="ow">in</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">):</span>
                <span class="k">return</span> <span class="kc">False</span>
            <span class="k">if</span> <span class="n">switch</span> <span class="ow">in</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">):</span>
                <span class="k">return</span> <span class="kc">True</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Don&#39;t know how to handle extension_switch: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">switch</span><span class="p">)</span>

        <span class="c1"># TODO Treat HGH HGHK pseudos</span>

        <span class="c1"># As far as I know, other Abinit pseudos do not support SOC.</span>
        <span class="k">return</span> <span class="kc">False</span>


<span class="k">class</span> <span class="nc">NcAbinitPseudo</span><span class="p">(</span><span class="n">NcPseudo</span><span class="p">,</span> <span class="n">AbinitPseudo</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Norm-conserving pseudopotential in the Abinit format.&quot;&quot;&quot;</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">summary</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_summary</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">Z</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_zatom</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">Z_val</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Number of valence electrons.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_zion</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">l_max</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_lmax</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">l_local</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_lloc</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">nlcc_radius</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_rchrg</span>


<span class="k">class</span> <span class="nc">PawAbinitPseudo</span><span class="p">(</span><span class="n">PawPseudo</span><span class="p">,</span> <span class="n">AbinitPseudo</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Paw pseudopotential in the Abinit format.&quot;&quot;&quot;</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">paw_radius</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_r_cut</span>

    <span class="c1"># def orbitals(self):</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">supports_soc</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="kc">True</span>


<span class="k">class</span> <span class="nc">Hint</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Suggested value for the cutoff energy [Hartree units]</span>
<span class="sd">    and the cutoff energy for the dense grid (only for PAW pseudos).</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ecut</span><span class="p">,</span> <span class="n">pawecutdg</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ecut</span> <span class="o">=</span> <span class="n">ecut</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">pawecutdg</span> <span class="o">=</span> <span class="n">ecut</span> <span class="k">if</span> <span class="n">pawecutdg</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="n">pawecutdg</span>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">pawecutdg</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="s2">&quot;ecut: </span><span class="si">%s</span><span class="s2">, pawecutdg: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ecut</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">pawecutdg</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="s2">&quot;ecut: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ecut</span><span class="p">)</span>

    <span class="nd">@pmg_serialize</span>
    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return dictionary for MSONable protocol.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">dict</span><span class="p">(</span><span class="n">ecut</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">ecut</span><span class="p">,</span> <span class="n">pawecutdg</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">pawecutdg</span><span class="p">)</span>

    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Build instance from dictionary (MSONable protocol).&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="o">**</span><span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">d</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">k</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;@&quot;</span><span class="p">)})</span>


<span class="k">def</span> <span class="nf">_dict_from_lines</span><span class="p">(</span><span class="n">lines</span><span class="p">,</span> <span class="n">key_nums</span><span class="p">,</span> <span class="n">sep</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Helper function to parse formatted text structured like:</span>

<span class="sd">    value1 value2 ... sep key1, key2 ...</span>

<span class="sd">    key_nums is a list giving the number of keys for each line. 0 if line should be skipped.</span>
<span class="sd">    sep is a string denoting the character that separates the keys from the value (None if</span>
<span class="sd">    no separator is present).</span>

<span class="sd">    Returns:</span>
<span class="sd">        dict{key1 : value1, key2 : value2, ...}</span>

<span class="sd">    Raises:</span>
<span class="sd">        ValueError if parsing fails.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">is_string</span><span class="p">(</span><span class="n">lines</span><span class="p">):</span>
        <span class="n">lines</span> <span class="o">=</span> <span class="p">[</span><span class="n">lines</span><span class="p">]</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">key_nums</span><span class="p">,</span> <span class="n">collections</span><span class="o">.</span><span class="n">abc</span><span class="o">.</span><span class="n">Iterable</span><span class="p">):</span>
        <span class="n">key_nums</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">key_nums</span><span class="p">)</span>

    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">lines</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="n">key_nums</span><span class="p">):</span>
        <span class="n">err_msg</span> <span class="o">=</span> <span class="s2">&quot;lines = </span><span class="si">%s</span><span class="se">\n</span><span class="s2"> key_num =  </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">lines</span><span class="p">),</span> <span class="nb">str</span><span class="p">(</span><span class="n">key_nums</span><span class="p">))</span>
        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">err_msg</span><span class="p">)</span>

    <span class="n">kwargs</span> <span class="o">=</span> <span class="n">Namespace</span><span class="p">()</span>

    <span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">nk</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">key_nums</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">nk</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">continue</span>
        <span class="n">line</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>

        <span class="n">tokens</span> <span class="o">=</span> <span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span>
        <span class="n">values</span><span class="p">,</span> <span class="n">keys</span> <span class="o">=</span> <span class="n">tokens</span><span class="p">[:</span><span class="n">nk</span><span class="p">],</span> <span class="s2">&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">tokens</span><span class="p">[</span><span class="n">nk</span><span class="p">:])</span>
        <span class="c1"># Sanitize keys: In some case we might get strings in the form: foo[,bar]</span>
        <span class="n">keys</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">&quot;[&quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">&quot;]&quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span>
        <span class="n">keys</span> <span class="o">=</span> <span class="n">keys</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;,&quot;</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">sep</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">check</span> <span class="o">=</span> <span class="n">keys</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">check</span> <span class="o">!=</span> <span class="n">sep</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Expecting separator </span><span class="si">%s</span><span class="s2">, got </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">sep</span><span class="p">,</span> <span class="n">check</span><span class="p">))</span>
            <span class="n">keys</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">keys</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">:]</span>

        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">values</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="n">keys</span><span class="p">):</span>
            <span class="n">msg</span> <span class="o">=</span> <span class="s2">&quot;line: </span><span class="si">%s</span><span class="se">\n</span><span class="s2"> len(keys) != len(value)</span><span class="se">\n</span><span class="s2">keys: </span><span class="si">%s</span><span class="se">\n</span><span class="s2"> values: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">line</span><span class="p">,</span> <span class="n">keys</span><span class="p">,</span> <span class="n">values</span><span class="p">)</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>

        <span class="n">kwargs</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="nb">zip</span><span class="p">(</span><span class="n">keys</span><span class="p">,</span> <span class="n">values</span><span class="p">))</span>

    <span class="k">return</span> <span class="n">kwargs</span>


<span class="k">class</span> <span class="nc">AbinitHeader</span><span class="p">(</span><span class="nb">dict</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Dictionary whose keys can be also accessed as attributes.&quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__getattr__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="c1"># Default behaviour</span>
            <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__getattribute__</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="c1"># Try in the dictionary.</span>
                <span class="k">return</span> <span class="bp">self</span><span class="p">[</span><span class="n">name</span><span class="p">]</span>
            <span class="k">except</span> <span class="ne">KeyError</span> <span class="k">as</span> <span class="n">exc</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">AttributeError</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">exc</span><span class="p">))</span>


<span class="k">def</span> <span class="nf">_int_from_str</span><span class="p">(</span><span class="n">string</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Convert string into integer</span>

<span class="sd">    Raise:</span>
<span class="sd">        TypeError if string is not a valid integer</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">float_num</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">string</span><span class="p">)</span>
    <span class="n">int_num</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">float_num</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">float_num</span> <span class="o">==</span> <span class="n">int_num</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">int_num</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="c1"># Needed to handle pseudos with fractional charge</span>
        <span class="n">int_num</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">rint</span><span class="p">(</span><span class="n">float_num</span><span class="p">)</span>
        <span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s2">&quot;Converting float </span><span class="si">%s</span><span class="s2"> to int </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">float_num</span><span class="p">,</span> <span class="n">int_num</span><span class="p">))</span>
        <span class="k">return</span> <span class="n">int_num</span>


<span class="k">class</span> <span class="nc">NcAbinitHeader</span><span class="p">(</span><span class="n">AbinitHeader</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;The abinit header found in the NC pseudopotential files.&quot;&quot;&quot;</span>
    <span class="n">_attr_desc</span> <span class="o">=</span> <span class="n">namedtuple</span><span class="p">(</span><span class="s2">&quot;att&quot;</span><span class="p">,</span> <span class="s2">&quot;default astype&quot;</span><span class="p">)</span>

    <span class="n">_VARS</span> <span class="o">=</span> <span class="p">{</span>
        <span class="c1"># Mandatory</span>
        <span class="s2">&quot;zatom&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="n">_int_from_str</span><span class="p">),</span>
        <span class="s2">&quot;zion&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="nb">float</span><span class="p">),</span>
        <span class="s2">&quot;pspdat&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="nb">float</span><span class="p">),</span>
        <span class="s2">&quot;pspcod&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="nb">int</span><span class="p">),</span>
        <span class="s2">&quot;pspxc&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="nb">int</span><span class="p">),</span>
        <span class="s2">&quot;lmax&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="nb">int</span><span class="p">),</span>
        <span class="s2">&quot;lloc&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="nb">int</span><span class="p">),</span>
        <span class="s2">&quot;r2well&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="nb">float</span><span class="p">),</span>
        <span class="s2">&quot;mmax&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="nb">float</span><span class="p">),</span>
        <span class="c1"># Optional variables for non linear-core correction. HGH does not have it.</span>
        <span class="s2">&quot;rchrg&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span> <span class="nb">float</span><span class="p">),</span>  <span class="c1"># radius at which the core charge vanish (i.e. cut-off in a.u.)</span>
        <span class="s2">&quot;fchrg&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span> <span class="nb">float</span><span class="p">),</span>
        <span class="s2">&quot;qchrg&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span> <span class="nb">float</span><span class="p">),</span>
    <span class="p">}</span>
    <span class="k">del</span> <span class="n">_attr_desc</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">summary</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>

        <span class="c1"># pseudos generated by APE use llocal instead of lloc.</span>
        <span class="k">if</span> <span class="s2">&quot;llocal&quot;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
            <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;lloc&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">&quot;llocal&quot;</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">summary</span> <span class="o">=</span> <span class="n">summary</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>

        <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">desc</span> <span class="ow">in</span> <span class="n">NcAbinitHeader</span><span class="o">.</span><span class="n">_VARS</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">default</span><span class="p">,</span> <span class="n">astype</span> <span class="o">=</span> <span class="n">desc</span><span class="o">.</span><span class="n">default</span><span class="p">,</span> <span class="n">desc</span><span class="o">.</span><span class="n">astype</span>
            <span class="n">value</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

            <span class="k">if</span> <span class="n">value</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">value</span> <span class="o">=</span> <span class="n">default</span>
                <span class="k">if</span> <span class="n">default</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;Attribute </span><span class="si">%s</span><span class="s2"> must be specified&quot;</span> <span class="o">%</span> <span class="n">key</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">try</span><span class="p">:</span>
                    <span class="n">value</span> <span class="o">=</span> <span class="n">astype</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
                <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;Conversion Error for key </span><span class="si">%s</span><span class="s2">, value </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">))</span>

            <span class="bp">self</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>

        <span class="c1"># Add remaining arguments, e.g. extension_switch</span>
        <span class="k">if</span> <span class="n">kwargs</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">kwargs</span><span class="p">)</span>

    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">fhi_header</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">ppdesc</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Parse the FHI abinit header. Example:</span>

<span class="sd">        Troullier-Martins psp for element  Sc        Thu Oct 27 17:33:22 EDT 1994</span>
<span class="sd">         21.00000   3.00000    940714                zatom, zion, pspdat</span>
<span class="sd">           1    1    2    0      2001    .00000      pspcod,pspxc,lmax,lloc,mmax,r2well</span>
<span class="sd">        1.80626423934776     .22824404341771    1.17378968127746   rchrg,fchrg,qchrg</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">lines</span> <span class="o">=</span> <span class="n">_read_nlines</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="n">header</span> <span class="o">=</span> <span class="n">_dict_from_lines</span><span class="p">(</span><span class="n">lines</span><span class="p">[:</span><span class="mi">4</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
        <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
            <span class="c1"># The last record with rchrg ... seems to be optional.</span>
            <span class="n">header</span> <span class="o">=</span> <span class="n">_dict_from_lines</span><span class="p">(</span><span class="n">lines</span><span class="p">[:</span><span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">])</span>

        <span class="n">summary</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

        <span class="k">return</span> <span class="n">NcAbinitHeader</span><span class="p">(</span><span class="n">summary</span><span class="p">,</span> <span class="o">**</span><span class="n">header</span><span class="p">)</span>

    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">hgh_header</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">ppdesc</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Parse the HGH abinit header. Example:</span>

<span class="sd">        Hartwigsen-Goedecker-Hutter psp for Ne,  from PRB58, 3641 (1998)</span>
<span class="sd">           10   8  010605 zatom,zion,pspdat</span>
<span class="sd">         3 1   1 0 2001 0  pspcod,pspxc,lmax,lloc,mmax,r2well</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">lines</span> <span class="o">=</span> <span class="n">_read_nlines</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>

        <span class="n">header</span> <span class="o">=</span> <span class="n">_dict_from_lines</span><span class="p">(</span><span class="n">lines</span><span class="p">[:</span><span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">])</span>
        <span class="n">summary</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

        <span class="k">return</span> <span class="n">NcAbinitHeader</span><span class="p">(</span><span class="n">summary</span><span class="p">,</span> <span class="o">**</span><span class="n">header</span><span class="p">)</span>

    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">gth_header</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">ppdesc</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Parse the GTH abinit header. Example:</span>

<span class="sd">        Goedecker-Teter-Hutter  Wed May  8 14:27:44 EDT 1996</span>
<span class="sd">        1   1   960508                     zatom,zion,pspdat</span>
<span class="sd">        2   1   0    0    2001    0.       pspcod,pspxc,lmax,lloc,mmax,r2well</span>
<span class="sd">        0.2000000 -4.0663326  0.6778322 0 0     rloc, c1, c2, c3, c4</span>
<span class="sd">        0 0 0                              rs, h1s, h2s</span>
<span class="sd">        0 0                                rp, h1p</span>
<span class="sd">          1.36 .2   0.6                    rcutoff, rloc</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">lines</span> <span class="o">=</span> <span class="n">_read_nlines</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="mi">7</span><span class="p">)</span>

        <span class="n">header</span> <span class="o">=</span> <span class="n">_dict_from_lines</span><span class="p">(</span><span class="n">lines</span><span class="p">[:</span><span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">])</span>
        <span class="n">summary</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

        <span class="k">return</span> <span class="n">NcAbinitHeader</span><span class="p">(</span><span class="n">summary</span><span class="p">,</span> <span class="o">**</span><span class="n">header</span><span class="p">)</span>

    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">oncvpsp_header</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">ppdesc</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Parse the ONCVPSP abinit header. Example:</span>

<span class="sd">        Li    ONCVPSP  r_core=  2.01  3.02</span>
<span class="sd">              3.0000      3.0000      140504    zatom,zion,pspd</span>
<span class="sd">             8     2     1     4   600     0    pspcod,pspxc,lmax,lloc,mmax,r2well</span>
<span class="sd">          5.99000000  0.00000000  0.00000000    rchrg fchrg qchrg</span>
<span class="sd">             2     2     0     0     0    nproj</span>
<span class="sd">             0                 extension_switch</span>
<span class="sd">           0                        -2.5000025868368D+00 -1.2006906995331D+00</span>
<span class="sd">             1  0.0000000000000D+00  0.0000000000000D+00  0.0000000000000D+00</span>
<span class="sd">             2  1.0000000000000D-02  4.4140499497377D-02  1.9909081701712D-02</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">lines</span> <span class="o">=</span> <span class="n">_read_nlines</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span>

        <span class="n">header</span> <span class="o">=</span> <span class="n">_dict_from_lines</span><span class="p">(</span><span class="n">lines</span><span class="p">[:</span><span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">])</span>
        <span class="n">summary</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

        <span class="c1"># Replace pspd with pspdata</span>
        <span class="n">header</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="s1">&#39;pspdat&#39;</span><span class="p">:</span> <span class="n">header</span><span class="p">[</span><span class="s1">&#39;pspd&#39;</span><span class="p">]})</span>
        <span class="n">header</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;pspd&#39;</span><span class="p">)</span>

        <span class="c1"># Read extension switch</span>
        <span class="n">header</span><span class="p">[</span><span class="s2">&quot;extension_switch&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">lines</span><span class="p">[</span><span class="mi">5</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">0</span><span class="p">])</span>

        <span class="k">return</span> <span class="n">NcAbinitHeader</span><span class="p">(</span><span class="n">summary</span><span class="p">,</span> <span class="o">**</span><span class="n">header</span><span class="p">)</span>

    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">tm_header</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">ppdesc</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Parse the TM abinit header. Example:</span>

<span class="sd">        Troullier-Martins psp for element Fm         Thu Oct 27 17:28:39 EDT 1994</span>
<span class="sd">        100.00000  14.00000    940714                zatom, zion, pspdat</span>
<span class="sd">           1    1    3    0      2001    .00000      pspcod,pspxc,lmax,lloc,mmax,r2well</span>
<span class="sd">           0   4.085   6.246    0   2.8786493        l,e99.0,e99.9,nproj,rcpsp</span>
<span class="sd">           .00000000    .0000000000    .0000000000    .00000000   rms,ekb1,ekb2,epsatm</span>
<span class="sd">           1   3.116   4.632    1   3.4291849        l,e99.0,e99.9,nproj,rcpsp</span>
<span class="sd">           .00000000    .0000000000    .0000000000    .00000000   rms,ekb1,ekb2,epsatm</span>
<span class="sd">           2   4.557   6.308    1   2.1865358        l,e99.0,e99.9,nproj,rcpsp</span>
<span class="sd">           .00000000    .0000000000    .0000000000    .00000000   rms,ekb1,ekb2,epsatm</span>
<span class="sd">           3  23.251  29.387    1   2.4776730        l,e99.0,e99.9,nproj,rcpsp</span>
<span class="sd">           .00000000    .0000000000    .0000000000    .00000000   rms,ekb1,ekb2,epsatm</span>
<span class="sd">           3.62474762267880     .07409391739104    3.07937699839200   rchrg,fchrg,qchrg</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">lines</span> <span class="o">=</span> <span class="n">_read_nlines</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">header</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="k">for</span> <span class="n">lineno</span><span class="p">,</span> <span class="n">line</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">lines</span><span class="p">):</span>
            <span class="n">header</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">lineno</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                <span class="c1"># Read lmax.</span>
                <span class="n">tokens</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="n">pspcod</span><span class="p">,</span> <span class="n">pspxc</span><span class="p">,</span> <span class="n">lmax</span><span class="p">,</span> <span class="n">lloc</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="n">tokens</span><span class="p">[:</span><span class="mi">4</span><span class="p">])</span>
                <span class="n">mmax</span><span class="p">,</span> <span class="n">r2well</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="nb">float</span><span class="p">,</span> <span class="n">tokens</span><span class="p">[</span><span class="mi">4</span><span class="p">:</span><span class="mi">6</span><span class="p">])</span>
                <span class="c1"># if tokens[-1].strip() != &quot;pspcod,pspxc,lmax,lloc,mmax,r2well&quot;:</span>
                <span class="c1">#    raise RuntimeError(&quot;%s: Invalid line\n %s&quot;  % (filename, line))</span>

                <span class="n">lines</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="mi">3</span><span class="p">:]</span>
                <span class="k">break</span>

        <span class="c1"># TODO</span>
        <span class="c1"># Parse the section with the projectors.</span>
        <span class="c1"># 0   4.085   6.246    0   2.8786493        l,e99.0,e99.9,nproj,rcpsp</span>
        <span class="c1"># .00000000    .0000000000    .0000000000    .00000000   rms,ekb1,ekb2,epsatm</span>
        <span class="n">projectors</span> <span class="o">=</span> <span class="n">OrderedDict</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">idx</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="p">(</span><span class="n">lmax</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)):</span>
            <span class="n">line</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="n">idx</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">idx</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">proj_info</span> <span class="o">=</span> <span class="p">[</span><span class="n">line</span><span class="p">,</span> <span class="p">]</span>
            <span class="k">if</span> <span class="n">idx</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
                <span class="n">proj_info</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
                <span class="n">d</span> <span class="o">=</span> <span class="n">_dict_from_lines</span><span class="p">(</span><span class="n">proj_info</span><span class="p">,</span> <span class="p">[</span><span class="mi">5</span><span class="p">,</span> <span class="mi">4</span><span class="p">])</span>
                <span class="n">projectors</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;l&quot;</span><span class="p">])]</span> <span class="o">=</span> <span class="n">d</span>

        <span class="c1"># Add the last line with info on nlcc.</span>
        <span class="n">header</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">lines</span><span class="p">[</span><span class="n">idx</span> <span class="o">+</span> <span class="mi">1</span><span class="p">])</span>
        <span class="n">summary</span> <span class="o">=</span> <span class="n">header</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

        <span class="n">header</span> <span class="o">=</span> <span class="n">_dict_from_lines</span><span class="p">(</span><span class="n">header</span><span class="p">,</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>

        <span class="k">return</span> <span class="n">NcAbinitHeader</span><span class="p">(</span><span class="n">summary</span><span class="p">,</span> <span class="o">**</span><span class="n">header</span><span class="p">)</span>


<span class="k">class</span> <span class="nc">PawAbinitHeader</span><span class="p">(</span><span class="n">AbinitHeader</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;The abinit header found in the PAW pseudopotential files.&quot;&quot;&quot;</span>
    <span class="n">_attr_desc</span> <span class="o">=</span> <span class="n">namedtuple</span><span class="p">(</span><span class="s2">&quot;att&quot;</span><span class="p">,</span> <span class="s2">&quot;default astype&quot;</span><span class="p">)</span>

    <span class="n">_VARS</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s2">&quot;zatom&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="n">_int_from_str</span><span class="p">),</span>
        <span class="s2">&quot;zion&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="nb">float</span><span class="p">),</span>
        <span class="s2">&quot;pspdat&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="nb">float</span><span class="p">),</span>
        <span class="s2">&quot;pspcod&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="nb">int</span><span class="p">),</span>
        <span class="s2">&quot;pspxc&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="nb">int</span><span class="p">),</span>
        <span class="s2">&quot;lmax&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="nb">int</span><span class="p">),</span>
        <span class="s2">&quot;lloc&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="nb">int</span><span class="p">),</span>
        <span class="s2">&quot;mmax&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="nb">int</span><span class="p">),</span>
        <span class="s2">&quot;r2well&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="nb">float</span><span class="p">),</span>
        <span class="s2">&quot;pspfmt&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="nb">str</span><span class="p">),</span>
        <span class="s2">&quot;creatorID&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="nb">int</span><span class="p">),</span>
        <span class="s2">&quot;basis_size&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="nb">int</span><span class="p">),</span>
        <span class="s2">&quot;lmn_size&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="nb">int</span><span class="p">),</span>
        <span class="s2">&quot;orbitals&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="nb">list</span><span class="p">),</span>
        <span class="s2">&quot;number_of_meshes&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="nb">int</span><span class="p">),</span>
        <span class="s2">&quot;r_cut&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="nb">float</span><span class="p">),</span>  <span class="c1"># r_cut(PAW) in the header</span>
        <span class="s2">&quot;shape_type&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="nb">int</span><span class="p">),</span>
        <span class="s2">&quot;rshape&quot;</span><span class="p">:</span> <span class="n">_attr_desc</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="nb">float</span><span class="p">),</span>
    <span class="p">}</span>
    <span class="k">del</span> <span class="n">_attr_desc</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">summary</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">summary</span> <span class="o">=</span> <span class="n">summary</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>

        <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">desc</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_VARS</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">default</span><span class="p">,</span> <span class="n">astype</span> <span class="o">=</span> <span class="n">desc</span><span class="o">.</span><span class="n">default</span><span class="p">,</span> <span class="n">desc</span><span class="o">.</span><span class="n">astype</span>

            <span class="n">value</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

            <span class="k">if</span> <span class="n">value</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">value</span> <span class="o">=</span> <span class="n">default</span>
                <span class="k">if</span> <span class="n">default</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;Attribute </span><span class="si">%s</span><span class="s2"> must be specified&quot;</span> <span class="o">%</span> <span class="n">key</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">try</span><span class="p">:</span>
                    <span class="n">value</span> <span class="o">=</span> <span class="n">astype</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
                <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;Conversion Error for key </span><span class="si">%s</span><span class="s2">, with value </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">))</span>

            <span class="bp">self</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>

        <span class="k">if</span> <span class="n">kwargs</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;kwargs should be empty but got </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="nb">str</span><span class="p">(</span><span class="n">kwargs</span><span class="p">))</span>

    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">paw_header</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">ppdesc</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Parse the PAW abinit header. Examples:</span>

<span class="sd">        Paw atomic data for element Ni - Generated by AtomPAW (N. Holzwarth) + AtomPAW2Abinit v3.0.5</span>
<span class="sd">          28.000  18.000 20061204               : zatom,zion,pspdat</span>
<span class="sd">          7  7  2 0   350 0.                    : pspcod,pspxc,lmax,lloc,mmax,r2well</span>
<span class="sd">         paw3 1305                              : pspfmt,creatorID</span>
<span class="sd">          5 13                                  : basis_size,lmn_size</span>
<span class="sd">         0 0 1 1 2                              : orbitals</span>
<span class="sd">         3                                      : number_of_meshes</span>
<span class="sd">         1 3  350 1.1803778368E-05 3.5000000000E-02 : mesh 1, type,size,rad_step[,log_step]</span>
<span class="sd">         2 1  921 2.500000000000E-03                : mesh 2, type,size,rad_step[,log_step]</span>
<span class="sd">         3 3  391 1.1803778368E-05 3.5000000000E-02 : mesh 3, type,size,rad_step[,log_step]</span>
<span class="sd">          2.3000000000                          : r_cut(SPH)</span>
<span class="sd">         2 0.</span>

<span class="sd">        Another format:</span>

<span class="sd">        C  (US d-loc) - PAW data extracted from US-psp (D.Vanderbilt) - generated by USpp2Abinit v2.3.0</span>
<span class="sd">           6.000   4.000 20090106               : zatom,zion,pspdat</span>
<span class="sd">          7 11  1 0   560 0.                    : pspcod,pspxc,lmax,lloc,mmax,r2well</span>
<span class="sd">         paw4 2230                              : pspfmt,creatorID</span>
<span class="sd">          4  8                                  : basis_size,lmn_size</span>
<span class="sd">         0 0 1 1                                : orbitals</span>
<span class="sd">         5                                      : number_of_meshes</span>
<span class="sd">         1 2  560 1.5198032759E-04 1.6666666667E-02 : mesh 1, type,size,rad_step[,log_step]</span>
<span class="sd">         2 2  556 1.5198032759E-04 1.6666666667E-02 : mesh 2, type,size,rad_step[,log_step]</span>
<span class="sd">         3 2  576 1.5198032759E-04 1.6666666667E-02 : mesh 3, type,size,rad_step[,log_step]</span>
<span class="sd">         4 2  666 1.5198032759E-04 1.6666666667E-02 : mesh 4, type,size,rad_step[,log_step]</span>
<span class="sd">         5 2  673 1.5198032759E-04 1.6666666667E-02 : mesh 5, type,size,rad_step[,log_step]</span>
<span class="sd">          1.5550009124                          : r_cut(PAW)</span>
<span class="sd">         3 0.                                   : shape_type,rshape</span>

<span class="sd">        Yet nnother one:</span>

<span class="sd">        Paw atomic data for element Si - Generated by atompaw v3.0.1.3 &amp; AtomPAW2Abinit v3.3.1</span>
<span class="sd">          14.000   4.000 20120814               : zatom,zion,pspdat</span>
<span class="sd">          7      11  1 0   663 0.               : pspcod,pspxc,lmax,lloc,mmax,r2well</span>
<span class="sd">         paw5 1331                              : pspfmt,creatorID</span>
<span class="sd">          4  8                                  : basis_size,lmn_size</span>
<span class="sd">         0 0 1 1                                : orbitals</span>
<span class="sd">         5                                      : number_of_meshes</span>
<span class="sd">         1 2  663 8.2129718540404674E-04 1.1498160595656655E-02 : mesh 1, type,size,rad_step[,log_step]</span>
<span class="sd">         2 2  658 8.2129718540404674E-04 1.1498160595656655E-02 : mesh 2, type,size,rad_step[,log_step]</span>
<span class="sd">         3 2  740 8.2129718540404674E-04 1.1498160595656655E-02 : mesh 3, type,size,rad_step[,log_step]</span>
<span class="sd">         4 2  819 8.2129718540404674E-04 1.1498160595656655E-02 : mesh 4, type,size,rad_step[,log_step]</span>
<span class="sd">         5 2  870 8.2129718540404674E-04 1.1498160595656655E-02 : mesh 5, type,size,rad_step[,log_step]</span>
<span class="sd">          1.5669671236                          : r_cut(PAW)</span>
<span class="sd">         2 0.                                   : shape_type,rshape</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">supported_formats</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;paw3&quot;</span><span class="p">,</span> <span class="s2">&quot;paw4&quot;</span><span class="p">,</span> <span class="s2">&quot;paw5&quot;</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">ppdesc</span><span class="o">.</span><span class="n">format</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">supported_formats</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s2">&quot;format </span><span class="si">%s</span><span class="s2"> not in </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">ppdesc</span><span class="o">.</span><span class="n">format</span><span class="p">,</span> <span class="n">supported_formats</span><span class="p">))</span>

        <span class="n">lines</span> <span class="o">=</span> <span class="n">_read_nlines</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span>

        <span class="n">summary</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">header</span> <span class="o">=</span> <span class="n">_dict_from_lines</span><span class="p">(</span><span class="n">lines</span><span class="p">[:</span><span class="mi">5</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">sep</span><span class="o">=</span><span class="s2">&quot;:&quot;</span><span class="p">)</span>

        <span class="n">lines</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="mi">5</span><span class="p">:]</span>
        <span class="c1"># TODO</span>
        <span class="c1"># Parse orbitals and number of meshes.</span>
        <span class="n">header</span><span class="p">[</span><span class="s2">&quot;orbitals&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">t</span><span class="p">)</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">lines</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;:&quot;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span>
        <span class="n">header</span><span class="p">[</span><span class="s2">&quot;number_of_meshes&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">num_meshes</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;:&quot;</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span>
        <span class="c1"># print filename, header</span>

        <span class="c1"># Skip meshes =</span>
        <span class="n">lines</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="mi">2</span> <span class="o">+</span> <span class="n">num_meshes</span><span class="p">:]</span>
        <span class="c1"># for midx in range(num_meshes):</span>
        <span class="c1">#    l = midx + 1</span>

        <span class="c1"># print lines[0]</span>
        <span class="n">header</span><span class="p">[</span><span class="s2">&quot;r_cut&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">lines</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;:&quot;</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span>
        <span class="c1"># print lines[1]</span>
        <span class="n">header</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">_dict_from_lines</span><span class="p">(</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">sep</span><span class="o">=</span><span class="s2">&quot;:&quot;</span><span class="p">))</span>

        <span class="c1"># print(&quot;PAW header\n&quot;, header)</span>
        <span class="k">return</span> <span class="n">PawAbinitHeader</span><span class="p">(</span><span class="n">summary</span><span class="p">,</span> <span class="o">**</span><span class="n">header</span><span class="p">)</span>


<span class="k">class</span> <span class="nc">PseudoParserError</span><span class="p">(</span><span class="ne">Exception</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Base Error class for the exceptions raised by :class:`PseudoParser`&quot;&quot;&quot;</span>


<span class="k">class</span> <span class="nc">PseudoParser</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Responsible for parsing pseudopotential files and returning pseudopotential objects.</span>

<span class="sd">    Usage::</span>

<span class="sd">        pseudo = PseudoParser().parse(&quot;filename&quot;)</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">Error</span> <span class="o">=</span> <span class="n">PseudoParserError</span>

    <span class="c1"># Supported values of pspcod</span>
    <span class="n">ppdesc</span> <span class="o">=</span> <span class="n">namedtuple</span><span class="p">(</span><span class="s2">&quot;ppdesc&quot;</span><span class="p">,</span> <span class="s2">&quot;pspcod name psp_type format&quot;</span><span class="p">)</span>

    <span class="c1"># TODO Recheck</span>
    <span class="n">_PSPCODES</span> <span class="o">=</span> <span class="n">OrderedDict</span><span class="p">({</span>
        <span class="mi">1</span><span class="p">:</span> <span class="n">ppdesc</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;TM&quot;</span><span class="p">,</span> <span class="s2">&quot;NC&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">),</span>
        <span class="mi">2</span><span class="p">:</span> <span class="n">ppdesc</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="s2">&quot;GTH&quot;</span><span class="p">,</span> <span class="s2">&quot;NC&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">),</span>
        <span class="mi">3</span><span class="p">:</span> <span class="n">ppdesc</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="s2">&quot;HGH&quot;</span><span class="p">,</span> <span class="s2">&quot;NC&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">),</span>
        <span class="mi">4</span><span class="p">:</span> <span class="n">ppdesc</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="s2">&quot;Teter&quot;</span><span class="p">,</span> <span class="s2">&quot;NC&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">),</span>
        <span class="c1"># 5: ppdesc(5, &quot;NC&quot;,     , None),</span>
        <span class="mi">6</span><span class="p">:</span> <span class="n">ppdesc</span><span class="p">(</span><span class="mi">6</span><span class="p">,</span> <span class="s2">&quot;FHI&quot;</span><span class="p">,</span> <span class="s2">&quot;NC&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">),</span>
        <span class="mi">7</span><span class="p">:</span> <span class="n">ppdesc</span><span class="p">(</span><span class="mi">6</span><span class="p">,</span> <span class="s2">&quot;PAW_abinit_text&quot;</span><span class="p">,</span> <span class="s2">&quot;PAW&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">),</span>
        <span class="mi">8</span><span class="p">:</span> <span class="n">ppdesc</span><span class="p">(</span><span class="mi">8</span><span class="p">,</span> <span class="s2">&quot;ONCVPSP&quot;</span><span class="p">,</span> <span class="s2">&quot;NC&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">),</span>
        <span class="mi">10</span><span class="p">:</span> <span class="n">ppdesc</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="s2">&quot;HGHK&quot;</span><span class="p">,</span> <span class="s2">&quot;NC&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">),</span>
    <span class="p">})</span>
    <span class="k">del</span> <span class="n">ppdesc</span>

    <span class="c1"># renumber functionals from oncvpsp todo confrim that 3 is 2</span>
    <span class="c1"># _FUNCTIONALS = {1: {&#39;n&#39;: 4, &#39;name&#39;: &#39;Wigner&#39;},</span>
    <span class="c1">#                2: {&#39;n&#39;: 5, &#39;name&#39;: &#39;HL&#39;},</span>
    <span class="c1">#                3: {&#39;n&#39;: 2, &#39;name&#39;: &#39;PWCA&#39;},</span>
    <span class="c1">#                4: {&#39;n&#39;: 11, &#39;name&#39;: &#39;PBE&#39;}}</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="c1"># List of files that have been parsed succesfully.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_parsed_paths</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="c1"># List of files that could not been parsed.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_wrong_paths</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">def</span> <span class="nf">scan_directory</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dirname</span><span class="p">,</span> <span class="n">exclude_exts</span><span class="o">=</span><span class="p">(),</span> <span class="n">exclude_fnames</span><span class="o">=</span><span class="p">()):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Analyze the files contained in directory dirname.</span>

<span class="sd">        Args:</span>
<span class="sd">            dirname: directory path</span>
<span class="sd">            exclude_exts: list of file extensions that should be skipped.</span>
<span class="sd">            exclude_fnames: list of file names that should be skipped.</span>

<span class="sd">        Returns:</span>
<span class="sd">            List of pseudopotential objects.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">ext</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">exclude_exts</span><span class="p">):</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">ext</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;.&quot;</span><span class="p">):</span>
                <span class="n">exclude_exts</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;.&quot;</span> <span class="o">+</span> <span class="n">ext</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>

        <span class="c1"># Exclude files depending on the extension.</span>
        <span class="n">paths</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">fname</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">listdir</span><span class="p">(</span><span class="n">dirname</span><span class="p">):</span>
            <span class="n">root</span><span class="p">,</span> <span class="n">ext</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">splitext</span><span class="p">(</span><span class="n">fname</span><span class="p">)</span>
            <span class="n">path</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">dirname</span><span class="p">,</span> <span class="n">fname</span><span class="p">)</span>
            <span class="k">if</span> <span class="p">(</span><span class="n">ext</span> <span class="ow">in</span> <span class="n">exclude_exts</span> <span class="ow">or</span> <span class="n">fname</span> <span class="ow">in</span> <span class="n">exclude_fnames</span> <span class="ow">or</span>
                    <span class="n">fname</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;.&quot;</span><span class="p">)</span> <span class="ow">or</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="n">path</span><span class="p">)):</span>
                <span class="k">continue</span>
            <span class="n">paths</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>

        <span class="n">pseudos</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">path</span> <span class="ow">in</span> <span class="n">paths</span><span class="p">:</span>
            <span class="c1"># Parse the file and generate the pseudo.</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">pseudo</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
            <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
                <span class="n">pseudo</span> <span class="o">=</span> <span class="kc">None</span>

            <span class="k">if</span> <span class="n">pseudo</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">pseudos</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pseudo</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_parsed_paths</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_wrong_paths</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">pseudos</span>

    <span class="k">def</span> <span class="nf">read_ppdesc</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Read the pseudopotential descriptor from file filename.</span>

<span class="sd">        Returns:</span>
<span class="sd">            Pseudopotential descriptor. None if filename is not a valid pseudopotential file.</span>

<span class="sd">        Raises:</span>
<span class="sd">            `PseudoParserError` if fileformat is not supported.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">filename</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s2">&quot;.xml&quot;</span><span class="p">):</span>
            <span class="k">raise</span> <span class="bp">self</span><span class="o">.</span><span class="n">Error</span><span class="p">(</span><span class="s2">&quot;XML pseudo not supported yet&quot;</span><span class="p">)</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># Assume file with the abinit header.</span>
            <span class="n">lines</span> <span class="o">=</span> <span class="n">_read_nlines</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="mi">80</span><span class="p">)</span>

            <span class="k">for</span> <span class="n">lineno</span><span class="p">,</span> <span class="n">line</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">lines</span><span class="p">):</span>

                <span class="k">if</span> <span class="n">lineno</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                    <span class="k">try</span><span class="p">:</span>
                        <span class="n">tokens</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                        <span class="n">pspcod</span><span class="p">,</span> <span class="n">pspxc</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="n">tokens</span><span class="p">[:</span><span class="mi">2</span><span class="p">])</span>
                    <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
                        <span class="n">msg</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2">: Cannot parse pspcod, pspxc in line</span><span class="se">\n</span><span class="s2"> </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">line</span><span class="p">)</span>
                        <span class="n">logger</span><span class="o">.</span><span class="n">critical</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>
                        <span class="k">return</span> <span class="kc">None</span>

                    <span class="c1"># if tokens[-1].strip().replace(&quot; &quot;,&quot;&quot;) not in [&quot;pspcod,pspxc,lmax,lloc,mmax,r2well&quot;,</span>
                    <span class="c1">#                              &quot;pspcod,pspxc,lmax,llocal,mmax,r2well&quot;]:</span>
                    <span class="c1">#    raise self.Error(&quot;%s: Invalid line\n %s&quot;  % (filename, line))</span>
                    <span class="c1">#    return None</span>

                    <span class="k">if</span> <span class="n">pspcod</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_PSPCODES</span><span class="p">:</span>
                        <span class="k">raise</span> <span class="bp">self</span><span class="o">.</span><span class="n">Error</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2">: Don&#39;t know how to handle pspcod </span><span class="si">%s</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">pspcod</span><span class="p">))</span>

                    <span class="n">ppdesc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_PSPCODES</span><span class="p">[</span><span class="n">pspcod</span><span class="p">]</span>

                    <span class="k">if</span> <span class="n">pspcod</span> <span class="o">==</span> <span class="mi">7</span><span class="p">:</span>
                        <span class="c1"># PAW -&gt; need to know the format pspfmt</span>
                        <span class="n">tokens</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="n">lineno</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                        <span class="n">pspfmt</span><span class="p">,</span> <span class="n">creatorID</span> <span class="o">=</span> <span class="n">tokens</span><span class="p">[:</span><span class="mi">2</span><span class="p">]</span>
                        <span class="c1"># if tokens[-1].strip() != &quot;pspfmt,creatorID&quot;:</span>
                        <span class="c1">#    raise self.Error(&quot;%s: Invalid line\n %s&quot; % (filename, line))</span>
                        <span class="c1">#    return None</span>

                        <span class="n">ppdesc</span> <span class="o">=</span> <span class="n">ppdesc</span><span class="o">.</span><span class="n">_replace</span><span class="p">(</span><span class="nb">format</span><span class="o">=</span><span class="n">pspfmt</span><span class="p">)</span>

                    <span class="k">return</span> <span class="n">ppdesc</span>

            <span class="k">return</span> <span class="kc">None</span>

    <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Read and parse a pseudopotential file. Main entry point for client code.</span>

<span class="sd">        Returns:</span>
<span class="sd">            pseudopotential object or None if filename is not a valid pseudopotential file.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">path</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>

        <span class="c1"># Only PAW supports XML at present.</span>
        <span class="k">if</span> <span class="n">filename</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s2">&quot;.xml&quot;</span><span class="p">):</span>
            <span class="k">return</span> <span class="n">PawXmlSetup</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>

        <span class="n">ppdesc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">read_ppdesc</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">ppdesc</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">logger</span><span class="o">.</span><span class="n">critical</span><span class="p">(</span><span class="s2">&quot;Cannot find ppdesc in </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">path</span><span class="p">)</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="n">psp_type</span> <span class="o">=</span> <span class="n">ppdesc</span><span class="o">.</span><span class="n">psp_type</span>

        <span class="n">parsers</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s2">&quot;FHI&quot;</span><span class="p">:</span> <span class="n">NcAbinitHeader</span><span class="o">.</span><span class="n">fhi_header</span><span class="p">,</span>
            <span class="s2">&quot;GTH&quot;</span><span class="p">:</span> <span class="n">NcAbinitHeader</span><span class="o">.</span><span class="n">gth_header</span><span class="p">,</span>
            <span class="s2">&quot;TM&quot;</span><span class="p">:</span> <span class="n">NcAbinitHeader</span><span class="o">.</span><span class="n">tm_header</span><span class="p">,</span>
            <span class="s2">&quot;Teter&quot;</span><span class="p">:</span> <span class="n">NcAbinitHeader</span><span class="o">.</span><span class="n">tm_header</span><span class="p">,</span>
            <span class="s2">&quot;HGH&quot;</span><span class="p">:</span> <span class="n">NcAbinitHeader</span><span class="o">.</span><span class="n">hgh_header</span><span class="p">,</span>
            <span class="s2">&quot;HGHK&quot;</span><span class="p">:</span> <span class="n">NcAbinitHeader</span><span class="o">.</span><span class="n">hgh_header</span><span class="p">,</span>
            <span class="s2">&quot;ONCVPSP&quot;</span><span class="p">:</span> <span class="n">NcAbinitHeader</span><span class="o">.</span><span class="n">oncvpsp_header</span><span class="p">,</span>
            <span class="s2">&quot;PAW_abinit_text&quot;</span><span class="p">:</span> <span class="n">PawAbinitHeader</span><span class="o">.</span><span class="n">paw_header</span><span class="p">,</span>
        <span class="p">}</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="n">header</span> <span class="o">=</span> <span class="n">parsers</span><span class="p">[</span><span class="n">ppdesc</span><span class="o">.</span><span class="n">name</span><span class="p">](</span><span class="n">path</span><span class="p">,</span> <span class="n">ppdesc</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
            <span class="k">raise</span> <span class="bp">self</span><span class="o">.</span><span class="n">Error</span><span class="p">(</span><span class="n">path</span> <span class="o">+</span> <span class="s2">&quot;:</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span> <span class="n">straceback</span><span class="p">())</span>

        <span class="k">if</span> <span class="n">psp_type</span> <span class="o">==</span> <span class="s2">&quot;NC&quot;</span><span class="p">:</span>
            <span class="n">pseudo</span> <span class="o">=</span> <span class="n">NcAbinitPseudo</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">header</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">psp_type</span> <span class="o">==</span> <span class="s2">&quot;PAW&quot;</span><span class="p">:</span>
            <span class="n">pseudo</span> <span class="o">=</span> <span class="n">PawAbinitPseudo</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">header</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s2">&quot;psp_type not in [NC, PAW]&quot;</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">pseudo</span>


<span class="c1"># TODO use RadialFunction from pseudo_dojo.</span>
<span class="k">class</span> <span class="nc">RadialFunction</span><span class="p">(</span><span class="n">namedtuple</span><span class="p">(</span><span class="s2">&quot;RadialFunction&quot;</span><span class="p">,</span> <span class="s2">&quot;mesh values&quot;</span><span class="p">)):</span>
    <span class="k">pass</span>


<span class="k">class</span> <span class="nc">PawXmlSetup</span><span class="p">(</span><span class="n">Pseudo</span><span class="p">,</span> <span class="n">PawPseudo</span><span class="p">):</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filepath</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">path</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="n">filepath</span><span class="p">)</span>

        <span class="c1"># Get the XML root (this trick is used to that the object is pickleable).</span>
        <span class="n">root</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">root</span>

        <span class="c1"># Get the version of the XML format</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">paw_setup_version</span> <span class="o">=</span> <span class="n">root</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;version&quot;</span><span class="p">)</span>

        <span class="c1"># Info on the atom.</span>
        <span class="n">atom_attrib</span> <span class="o">=</span> <span class="n">root</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;atom&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">attrib</span>

        <span class="c1"># self._symbol = atom_attrib[&quot;symbol&quot;]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_zatom</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">atom_attrib</span><span class="p">[</span><span class="s2">&quot;Z&quot;</span><span class="p">]))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">core</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">valence</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="nb">float</span><span class="p">,</span> <span class="p">[</span><span class="n">atom_attrib</span><span class="p">[</span><span class="s2">&quot;core&quot;</span><span class="p">],</span> <span class="n">atom_attrib</span><span class="p">[</span><span class="s2">&quot;valence&quot;</span><span class="p">]])</span>

        <span class="c1"># Build xc from header.</span>
        <span class="n">xc_info</span> <span class="o">=</span> <span class="n">root</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;xc_functional&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">attrib</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">xc</span> <span class="o">=</span> <span class="n">XcFunc</span><span class="o">.</span><span class="n">from_type_name</span><span class="p">(</span><span class="n">xc_info</span><span class="p">[</span><span class="s2">&quot;type&quot;</span><span class="p">],</span> <span class="n">xc_info</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">])</span>

        <span class="c1"># Old XML files do not define this field!</span>
        <span class="c1"># In this case we set the PAW radius to None.</span>
        <span class="c1"># self._paw_radius = float(root.find(&quot;PAW_radius&quot;).attrib[&quot;rpaw&quot;])</span>

        <span class="c1"># self.ae_energy = {k: float(v) for k,v in root.find(&quot;ae_energy&quot;).attrib.items()}</span>
        <span class="n">pawr_element</span> <span class="o">=</span> <span class="n">root</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;PAW_radius&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_paw_radius</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">if</span> <span class="n">pawr_element</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_paw_radius</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">pawr_element</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;rpaw&quot;</span><span class="p">])</span>

        <span class="c1"># &lt;valence_states&gt;</span>
        <span class="c1">#  &lt;state n=&quot;2&quot; l=&quot;0&quot; f=&quot;2&quot;  rc=&quot;1.10&quot; e=&quot;-0.6766&quot; id=&quot;N-2s&quot;/&gt;</span>
        <span class="c1">#  &lt;state n=&quot;2&quot; l=&quot;1&quot; f=&quot;3&quot;  rc=&quot;1.10&quot; e=&quot;-0.2660&quot; id=&quot;N-2p&quot;/&gt;</span>
        <span class="c1">#  &lt;state       l=&quot;0&quot;        rc=&quot;1.10&quot; e=&quot; 0.3234&quot; id=&quot;N-s1&quot;/&gt;</span>
        <span class="c1">#  &lt;state       l=&quot;1&quot;        rc=&quot;1.10&quot; e=&quot; 0.7340&quot; id=&quot;N-p1&quot;/&gt;</span>
        <span class="c1">#  &lt;state       l=&quot;2&quot;        rc=&quot;1.10&quot; e=&quot; 0.0000&quot; id=&quot;N-d1&quot;/&gt;</span>
        <span class="c1"># &lt;/valence_states&gt;</span>
        <span class="c1">#</span>
        <span class="c1"># The valence_states element contains several state elements.</span>
        <span class="c1"># For this setup, the first two lines describe bound eigenstates</span>
        <span class="c1"># with occupation numbers and principal quantum numbers.</span>
        <span class="c1"># Notice, that the three additional unbound states should have no f and n attributes.</span>
        <span class="c1"># In this way, we know that only the first two bound states (with f and n attributes)</span>
        <span class="c1"># should be used for constructing an initial guess for the wave functions.</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">valence_states</span> <span class="o">=</span> <span class="n">OrderedDict</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">node</span> <span class="ow">in</span> <span class="n">root</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;valence_states&quot;</span><span class="p">):</span>
            <span class="n">attrib</span> <span class="o">=</span> <span class="n">AttrDict</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">attrib</span><span class="p">)</span>
            <span class="k">assert</span> <span class="n">attrib</span><span class="o">.</span><span class="n">id</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">valence_states</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">valence_states</span><span class="p">[</span><span class="n">attrib</span><span class="o">.</span><span class="n">id</span><span class="p">]</span> <span class="o">=</span> <span class="n">attrib</span>
        <span class="c1"># print(self.valence_states)</span>

        <span class="c1"># Parse the radial grids</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">rad_grids</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">node</span> <span class="ow">in</span> <span class="n">root</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">&quot;radial_grid&quot;</span><span class="p">):</span>
            <span class="n">grid_params</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">attrib</span>
            <span class="n">gid</span> <span class="o">=</span> <span class="n">grid_params</span><span class="p">[</span><span class="s2">&quot;id&quot;</span><span class="p">]</span>
            <span class="k">assert</span> <span class="n">gid</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">rad_grids</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">rad_grids</span><span class="p">[</span><span class="n">gid</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_eval_grid</span><span class="p">(</span><span class="n">grid_params</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__getstate__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return state is pickled as the contents for the instance.</span>

<span class="sd">        In this case we just remove the XML root element process since Element object cannot be pickled.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__dict__</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> <span class="k">if</span> <span class="n">k</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;_root&quot;</span><span class="p">]}</span>

    <span class="nd">@lazy_property</span>
    <span class="k">def</span> <span class="nf">root</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="kn">from</span> <span class="nn">xml.etree</span> <span class="kn">import</span> <span class="n">cElementTree</span> <span class="k">as</span> <span class="n">Et</span>
        <span class="n">tree</span> <span class="o">=</span> <span class="n">Et</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filepath</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">tree</span><span class="o">.</span><span class="n">getroot</span><span class="p">()</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">Z</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_zatom</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">Z_val</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Number of valence electrons.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">valence</span>

    <span class="c1"># FIXME</span>
    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">l_max</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Maximum angular momentum.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="kc">None</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">l_local</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Angular momentum used for the local part.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="kc">None</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">summary</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;String summarizing the most important properties.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="s2">&quot;&quot;</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">paw_radius</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_paw_radius</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">supports_soc</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Here I assume that the ab-initio code can treat the SOC within the on-site approximation</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="kc">True</span>

    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">_eval_grid</span><span class="p">(</span><span class="n">grid_params</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        This function receives a dictionary with the parameters defining the</span>
<span class="sd">        radial mesh and returns a `ndarray` with the mesh</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">eq</span> <span class="o">=</span> <span class="n">grid_params</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;eq&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span>
        <span class="n">istart</span><span class="p">,</span> <span class="n">iend</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">grid_params</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;istart&quot;</span><span class="p">)),</span> <span class="nb">int</span><span class="p">(</span><span class="n">grid_params</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;iend&quot;</span><span class="p">))</span>
        <span class="n">indices</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="n">istart</span><span class="p">,</span> <span class="n">iend</span> <span class="o">+</span> <span class="mi">1</span><span class="p">))</span>

        <span class="k">if</span> <span class="n">eq</span> <span class="o">==</span> <span class="s1">&#39;r=a*exp(d*i)&#39;</span><span class="p">:</span>
            <span class="n">a</span><span class="p">,</span> <span class="n">d</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">grid_params</span><span class="p">[</span><span class="s1">&#39;a&#39;</span><span class="p">]),</span> <span class="nb">float</span><span class="p">(</span><span class="n">grid_params</span><span class="p">[</span><span class="s1">&#39;d&#39;</span><span class="p">])</span>
            <span class="n">mesh</span> <span class="o">=</span> <span class="p">[</span><span class="n">a</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="n">d</span> <span class="o">*</span> <span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">indices</span><span class="p">]</span>

        <span class="k">elif</span> <span class="n">eq</span> <span class="o">==</span> <span class="s1">&#39;r=a*i/(n-i)&#39;</span><span class="p">:</span>
            <span class="n">a</span><span class="p">,</span> <span class="n">n</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">grid_params</span><span class="p">[</span><span class="s1">&#39;a&#39;</span><span class="p">]),</span> <span class="nb">float</span><span class="p">(</span><span class="n">grid_params</span><span class="p">[</span><span class="s1">&#39;n&#39;</span><span class="p">])</span>
            <span class="n">mesh</span> <span class="o">=</span> <span class="p">[</span><span class="n">a</span> <span class="o">*</span> <span class="n">i</span> <span class="o">/</span> <span class="p">(</span><span class="n">n</span> <span class="o">-</span> <span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">indices</span><span class="p">]</span>

        <span class="k">elif</span> <span class="n">eq</span> <span class="o">==</span> <span class="s1">&#39;r=a*(exp(d*i)-1)&#39;</span><span class="p">:</span>
            <span class="n">a</span><span class="p">,</span> <span class="n">d</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">grid_params</span><span class="p">[</span><span class="s1">&#39;a&#39;</span><span class="p">]),</span> <span class="nb">float</span><span class="p">(</span><span class="n">grid_params</span><span class="p">[</span><span class="s1">&#39;d&#39;</span><span class="p">])</span>
            <span class="n">mesh</span> <span class="o">=</span> <span class="p">[</span><span class="n">a</span> <span class="o">*</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="n">d</span> <span class="o">*</span> <span class="n">i</span><span class="p">)</span> <span class="o">-</span> <span class="mf">1.0</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">indices</span><span class="p">]</span>

        <span class="k">elif</span> <span class="n">eq</span> <span class="o">==</span> <span class="s1">&#39;r=d*i&#39;</span><span class="p">:</span>
            <span class="n">d</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">grid_params</span><span class="p">[</span><span class="s1">&#39;d&#39;</span><span class="p">])</span>
            <span class="n">mesh</span> <span class="o">=</span> <span class="p">[</span><span class="n">d</span> <span class="o">*</span> <span class="n">i</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">indices</span><span class="p">]</span>

        <span class="k">elif</span> <span class="n">eq</span> <span class="o">==</span> <span class="s1">&#39;r=(i/n+a)^5/a-a^4&#39;</span><span class="p">:</span>
            <span class="n">a</span><span class="p">,</span> <span class="n">n</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">grid_params</span><span class="p">[</span><span class="s1">&#39;a&#39;</span><span class="p">]),</span> <span class="nb">float</span><span class="p">(</span><span class="n">grid_params</span><span class="p">[</span><span class="s1">&#39;n&#39;</span><span class="p">])</span>
            <span class="n">mesh</span> <span class="o">=</span> <span class="p">[(</span><span class="n">i</span> <span class="o">/</span> <span class="n">n</span> <span class="o">+</span> <span class="n">a</span><span class="p">)</span> <span class="o">**</span> <span class="mi">5</span> <span class="o">/</span> <span class="n">a</span> <span class="o">-</span> <span class="n">a</span> <span class="o">**</span> <span class="mi">4</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">indices</span><span class="p">]</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Unknown grid type: </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">eq</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">mesh</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_parse_radfunc</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">func_name</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Parse the first occurence of func_name in the XML file.&quot;&quot;&quot;</span>
        <span class="n">node</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">root</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="n">func_name</span><span class="p">)</span>
        <span class="n">grid</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;grid&quot;</span><span class="p">]</span>
        <span class="n">values</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">s</span><span class="p">)</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">node</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">split</span><span class="p">()])</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">rad_grids</span><span class="p">[</span><span class="n">grid</span><span class="p">],</span> <span class="n">values</span><span class="p">,</span> <span class="n">node</span><span class="o">.</span><span class="n">attrib</span>

    <span class="k">def</span> <span class="nf">_parse_all_radfuncs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">func_name</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Parse all the nodes with tag func_name in the XML file.&quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">node</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">root</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="n">func_name</span><span class="p">):</span>
            <span class="n">grid</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;grid&quot;</span><span class="p">]</span>
            <span class="n">values</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">s</span><span class="p">)</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">node</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">split</span><span class="p">()])</span>

            <span class="k">yield</span> <span class="bp">self</span><span class="o">.</span><span class="n">rad_grids</span><span class="p">[</span><span class="n">grid</span><span class="p">],</span> <span class="n">values</span><span class="p">,</span> <span class="n">node</span><span class="o">.</span><span class="n">attrib</span>

    <span class="nd">@lazy_property</span>
    <span class="k">def</span> <span class="nf">ae_core_density</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;The all-electron radial density.&quot;&quot;&quot;</span>
        <span class="n">mesh</span><span class="p">,</span> <span class="n">values</span><span class="p">,</span> <span class="n">attrib</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_radfunc</span><span class="p">(</span><span class="s2">&quot;ae_core_density&quot;</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">RadialFunction</span><span class="p">(</span><span class="n">mesh</span><span class="p">,</span> <span class="n">values</span><span class="p">)</span>

    <span class="nd">@lazy_property</span>
    <span class="k">def</span> <span class="nf">pseudo_core_density</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;The pseudized radial density.&quot;&quot;&quot;</span>
        <span class="n">mesh</span><span class="p">,</span> <span class="n">values</span><span class="p">,</span> <span class="n">attrib</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_radfunc</span><span class="p">(</span><span class="s2">&quot;pseudo_core_density&quot;</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">RadialFunction</span><span class="p">(</span><span class="n">mesh</span><span class="p">,</span> <span class="n">values</span><span class="p">)</span>

    <span class="nd">@lazy_property</span>
    <span class="k">def</span> <span class="nf">ae_partial_waves</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Dictionary with the AE partial waves indexed by state.&quot;&quot;&quot;</span>
        <span class="n">ae_partial_waves</span> <span class="o">=</span> <span class="n">OrderedDict</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">mesh</span><span class="p">,</span> <span class="n">values</span><span class="p">,</span> <span class="n">attrib</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_all_radfuncs</span><span class="p">(</span><span class="s2">&quot;ae_partial_wave&quot;</span><span class="p">):</span>
            <span class="n">state</span> <span class="o">=</span> <span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;state&quot;</span><span class="p">]</span>
            <span class="c1"># val_state = self.valence_states[state]</span>
            <span class="n">ae_partial_waves</span><span class="p">[</span><span class="n">state</span><span class="p">]</span> <span class="o">=</span> <span class="n">RadialFunction</span><span class="p">(</span><span class="n">mesh</span><span class="p">,</span> <span class="n">values</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">ae_partial_waves</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">pseudo_partial_waves</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Dictionary with the pseudo partial waves indexed by state.&quot;&quot;&quot;</span>
        <span class="n">pseudo_partial_waves</span> <span class="o">=</span> <span class="n">OrderedDict</span><span class="p">()</span>
        <span class="k">for</span> <span class="p">(</span><span class="n">mesh</span><span class="p">,</span> <span class="n">values</span><span class="p">,</span> <span class="n">attrib</span><span class="p">)</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_all_radfuncs</span><span class="p">(</span><span class="s2">&quot;pseudo_partial_wave&quot;</span><span class="p">):</span>
            <span class="n">state</span> <span class="o">=</span> <span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;state&quot;</span><span class="p">]</span>
            <span class="c1"># val_state = self.valence_states[state]</span>
            <span class="n">pseudo_partial_waves</span><span class="p">[</span><span class="n">state</span><span class="p">]</span> <span class="o">=</span> <span class="n">RadialFunction</span><span class="p">(</span><span class="n">mesh</span><span class="p">,</span> <span class="n">values</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">pseudo_partial_waves</span>

    <span class="nd">@lazy_property</span>
    <span class="k">def</span> <span class="nf">projector_functions</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Dictionary with the PAW projectors indexed by state.&quot;&quot;&quot;</span>
        <span class="n">projector_functions</span> <span class="o">=</span> <span class="n">OrderedDict</span><span class="p">()</span>
        <span class="k">for</span> <span class="p">(</span><span class="n">mesh</span><span class="p">,</span> <span class="n">values</span><span class="p">,</span> <span class="n">attrib</span><span class="p">)</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_all_radfuncs</span><span class="p">(</span><span class="s2">&quot;projector_function&quot;</span><span class="p">):</span>
            <span class="n">state</span> <span class="o">=</span> <span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;state&quot;</span><span class="p">]</span>
            <span class="c1"># val_state = self.valence_states[state]</span>
            <span class="n">projector_functions</span><span class="p">[</span><span class="n">state</span><span class="p">]</span> <span class="o">=</span> <span class="n">RadialFunction</span><span class="p">(</span><span class="n">mesh</span><span class="p">,</span> <span class="n">values</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">projector_functions</span>

    <span class="k">def</span> <span class="nf">yield_figs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>  <span class="c1"># pragma: no cover</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        This function *generates* a predefined list of matplotlib figures with minimal input from the user.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">yield</span> <span class="bp">self</span><span class="o">.</span><span class="n">plot_densities</span><span class="p">(</span><span class="n">title</span><span class="o">=</span><span class="s2">&quot;PAW densities&quot;</span><span class="p">,</span> <span class="n">show</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
        <span class="k">yield</span> <span class="bp">self</span><span class="o">.</span><span class="n">plot_waves</span><span class="p">(</span><span class="n">title</span><span class="o">=</span><span class="s2">&quot;PAW waves&quot;</span><span class="p">,</span> <span class="n">show</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
        <span class="k">yield</span> <span class="bp">self</span><span class="o">.</span><span class="n">plot_projectors</span><span class="p">(</span><span class="n">title</span><span class="o">=</span><span class="s2">&quot;PAW projectors&quot;</span><span class="p">,</span> <span class="n">show</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
        <span class="c1"># yield self.plot_potentials(title=&quot;potentials&quot;, show=False)</span>

    <span class="nd">@add_fig_kwargs</span>
    <span class="k">def</span> <span class="nf">plot_densities</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Plot the PAW densities.</span>

<span class="sd">        Args:</span>
<span class="sd">            ax: matplotlib :class:`Axes` or None if a new figure should be created.</span>

<span class="sd">        Returns:</span>
<span class="sd">            `matplotlib` figure</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">ax</span><span class="p">,</span> <span class="n">fig</span><span class="p">,</span> <span class="n">plt</span> <span class="o">=</span> <span class="n">get_ax_fig_plt</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>

        <span class="n">ax</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;r [Bohr]&#39;</span><span class="p">)</span>
        <span class="c1"># ax.set_ylabel(&#39;density&#39;)</span>

        <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">den_name</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">([</span><span class="s2">&quot;ae_core_density&quot;</span><span class="p">,</span> <span class="s2">&quot;pseudo_core_density&quot;</span><span class="p">]):</span>
            <span class="n">rden</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">den_name</span><span class="p">)</span>
            <span class="n">label</span> <span class="o">=</span> <span class="s2">&quot;$n_c$&quot;</span> <span class="k">if</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">1</span> <span class="k">else</span> <span class="sa">r</span><span class="s2">&quot;$\tilde</span><span class="si">{n}</span><span class="s2">_c$&quot;</span>
            <span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">rden</span><span class="o">.</span><span class="n">mesh</span><span class="p">,</span> <span class="n">rden</span><span class="o">.</span><span class="n">mesh</span> <span class="o">*</span> <span class="n">rden</span><span class="o">.</span><span class="n">values</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span> <span class="n">lw</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>

        <span class="n">ax</span><span class="o">.</span><span class="n">legend</span><span class="p">(</span><span class="n">loc</span><span class="o">=</span><span class="s2">&quot;best&quot;</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">fig</span>

    <span class="nd">@add_fig_kwargs</span>
    <span class="k">def</span> <span class="nf">plot_waves</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">fontsize</span><span class="o">=</span><span class="mi">12</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Plot the AE and the pseudo partial waves.</span>

<span class="sd">        Args:</span>
<span class="sd">            ax: matplotlib :class:`Axes` or None if a new figure should be created.</span>
<span class="sd">            fontsize: fontsize for legends and titles</span>

<span class="sd">        Returns: `matplotlib` figure</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">ax</span><span class="p">,</span> <span class="n">fig</span><span class="p">,</span> <span class="n">plt</span> <span class="o">=</span> <span class="n">get_ax_fig_plt</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>

        <span class="n">ax</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s2">&quot;r [Bohr]&quot;</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;$r\phi,\, r\tilde\phi\, [Bohr]^{-\frac</span><span class="si">{1}{2}</span><span class="s2">}$&quot;</span><span class="p">)</span>

        <span class="c1"># ax.axvline(x=self.paw_radius, linewidth=2, color=&#39;k&#39;, linestyle=&quot;--&quot;)</span>
        <span class="c1"># ax.annotate(&quot;$r_c$&quot;, xy=(self.paw_radius + 0.1, 0.1))</span>

        <span class="k">for</span> <span class="n">state</span><span class="p">,</span> <span class="n">rfunc</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">pseudo_partial_waves</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">rfunc</span><span class="o">.</span><span class="n">mesh</span><span class="p">,</span> <span class="n">rfunc</span><span class="o">.</span><span class="n">mesh</span> <span class="o">*</span> <span class="n">rfunc</span><span class="o">.</span><span class="n">values</span><span class="p">,</span> <span class="n">lw</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s2">&quot;PS-WAVE: &quot;</span> <span class="o">+</span> <span class="n">state</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">state</span><span class="p">,</span> <span class="n">rfunc</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">ae_partial_waves</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">rfunc</span><span class="o">.</span><span class="n">mesh</span><span class="p">,</span> <span class="n">rfunc</span><span class="o">.</span><span class="n">mesh</span> <span class="o">*</span> <span class="n">rfunc</span><span class="o">.</span><span class="n">values</span><span class="p">,</span> <span class="n">lw</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s2">&quot;AE-WAVE: &quot;</span> <span class="o">+</span> <span class="n">state</span><span class="p">)</span>

        <span class="n">ax</span><span class="o">.</span><span class="n">legend</span><span class="p">(</span><span class="n">loc</span><span class="o">=</span><span class="s2">&quot;best&quot;</span><span class="p">,</span> <span class="n">shadow</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">fontsize</span><span class="o">=</span><span class="n">fontsize</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">fig</span>

    <span class="nd">@add_fig_kwargs</span>
    <span class="k">def</span> <span class="nf">plot_projectors</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">fontsize</span><span class="o">=</span><span class="mi">12</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Plot the PAW projectors.</span>

<span class="sd">        Args:</span>
<span class="sd">            ax: matplotlib :class:`Axes` or None if a new figure should be created.</span>

<span class="sd">        Returns: `matplotlib` figure</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">ax</span><span class="p">,</span> <span class="n">fig</span><span class="p">,</span> <span class="n">plt</span> <span class="o">=</span> <span class="n">get_ax_fig_plt</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="n">title</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">&quot;title&quot;</span><span class="p">,</span> <span class="s2">&quot;Projectors&quot;</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;r [Bohr]&#39;</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;$r\tilde p\, [Bohr]^{-\frac</span><span class="si">{1}{2}</span><span class="s2">}$&quot;</span><span class="p">)</span>

        <span class="c1"># ax.axvline(x=self.paw_radius, linewidth=2, color=&#39;k&#39;, linestyle=&quot;--&quot;)</span>
        <span class="c1"># ax.annotate(&quot;$r_c$&quot;, xy=(self.paw_radius + 0.1, 0.1))</span>

        <span class="k">for</span> <span class="n">state</span><span class="p">,</span> <span class="n">rfunc</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">projector_functions</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">rfunc</span><span class="o">.</span><span class="n">mesh</span><span class="p">,</span> <span class="n">rfunc</span><span class="o">.</span><span class="n">mesh</span> <span class="o">*</span> <span class="n">rfunc</span><span class="o">.</span><span class="n">values</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s2">&quot;TPROJ: &quot;</span> <span class="o">+</span> <span class="n">state</span><span class="p">)</span>

        <span class="n">ax</span><span class="o">.</span><span class="n">legend</span><span class="p">(</span><span class="n">loc</span><span class="o">=</span><span class="s2">&quot;best&quot;</span><span class="p">,</span> <span class="n">shadow</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">fontsize</span><span class="o">=</span><span class="n">fontsize</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">fig</span>

    <span class="c1"># @add_fig_kwargs</span>
    <span class="c1"># def plot_potentials(self, **kwargs):</span>
    <span class="c1">#    &quot;&quot;&quot;</span>
    <span class="c1">#        ================  ==============================================================</span>
    <span class="c1">#        kwargs            Meaning</span>
    <span class="c1">#        ================  ==============================================================</span>
    <span class="c1">#        title             Title of the plot (Default: None).</span>
    <span class="c1">#        show              True to show the figure (Default).</span>
    <span class="c1">#        savefig           &#39;abc.png&#39; or &#39;abc.eps&#39; to save the figure to a file.</span>
    <span class="c1">#        ================  ==============================================================</span>

    <span class="c1">#    Returns:</span>
    <span class="c1">#        `matplotlib` figure</span>
    <span class="c1">#    &quot;&quot;&quot;</span>
    <span class="c1">#    title = kwargs.pop(&quot;title&quot;, &quot;Potentials&quot;)</span>
    <span class="c1">#    show = kwargs.pop(&quot;show&quot;, True)</span>
    <span class="c1">#    savefig = kwargs.pop(&quot;savefig&quot;, None)</span>

    <span class="c1">#    import matplotlib.pyplot as plt</span>

    <span class="c1">#    fig = plt.figure()</span>

    <span class="c1">#    ax = fig.add_subplot(1,1,1)</span>
    <span class="c1">#    ax.grid(True)</span>
    <span class="c1">#    ax.set_xlabel(&#39;r [Bohr]&#39;)</span>
    <span class="c1">#    ax.set_ylabel(&#39;density&#39;)</span>
    <span class="c1">#    ax.axvline(x=self.paw_radius, linewidth=2, color=&#39;k&#39;, linestyle=&quot;--&quot;)</span>
    <span class="c1">#    ax.annotate(&quot;$r_c$&quot;, xy=(self.paw_radius + 0.1, 0.1))</span>

    <span class="c1">#    for state, rfunc in self.potentials.items():</span>
    <span class="c1">#        ax.plot(rfunc.mesh, rfunc.values, label=&quot;TPROJ: &quot; + state)</span>

    <span class="c1">#    ax.legend(loc=&quot;best&quot;)</span>

    <span class="c1">#    if title is not None: fig.suptitle(title)</span>
    <span class="c1">#    if show: plt.show()</span>
    <span class="c1">#    if savefig: fig.savefig(savefig)</span>
    <span class="c1">#    return fig</span>


<div class="viewcode-block" id="PseudoTable"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.PseudoTable">[docs]</a><span class="k">class</span> <span class="nc">PseudoTable</span><span class="p">(</span><span class="n">collections</span><span class="o">.</span><span class="n">abc</span><span class="o">.</span><span class="n">Sequence</span><span class="p">,</span> <span class="n">MSONable</span><span class="p">,</span> <span class="n">metaclass</span><span class="o">=</span><span class="n">abc</span><span class="o">.</span><span class="n">ABCMeta</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Define the pseudopotentials from the element table.</span>
<span class="sd">    Individidual elements are accessed by name, symbol or atomic number.</span>

<span class="sd">    For example, the following all retrieve iron:</span>

<span class="sd">    print elements[26]</span>
<span class="sd">    Fe</span>
<span class="sd">    print elements.Fe</span>
<span class="sd">    Fe</span>
<span class="sd">    print elements.symbol(&#39;Fe&#39;)</span>
<span class="sd">    Fe</span>
<span class="sd">    print elements.name(&#39;iron&#39;)</span>
<span class="sd">    Fe</span>
<span class="sd">    print elements.isotope(&#39;Fe&#39;)</span>
<span class="sd">    Fe</span>
<span class="sd">    &quot;&quot;&quot;</span>

<div class="viewcode-block" id="PseudoTable.as_table"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.PseudoTable.as_table">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">as_table</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">items</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return an instance of :class:`PseudoTable` from the iterable items.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">items</span><span class="p">,</span> <span class="bp">cls</span><span class="p">):</span>
            <span class="k">return</span> <span class="n">items</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">items</span><span class="p">)</span></div>

<div class="viewcode-block" id="PseudoTable.from_dir"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.PseudoTable.from_dir">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dir</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">top</span><span class="p">,</span> <span class="n">exts</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">exclude_dirs</span><span class="o">=</span><span class="s2">&quot;_*&quot;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Find all pseudos in the directory tree starting from top.</span>

<span class="sd">        Args:</span>
<span class="sd">            top: Top of the directory tree</span>
<span class="sd">            exts: List of files extensions. if exts == &quot;all_files&quot;</span>
<span class="sd">                    we try to open all files in top</span>
<span class="sd">            exclude_dirs: Wildcard used to exclude directories.</span>

<span class="sd">        return: :class:`PseudoTable` sorted by atomic number Z.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">pseudos</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="k">if</span> <span class="n">exts</span> <span class="o">==</span> <span class="s2">&quot;all_files&quot;</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="p">[</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">top</span><span class="p">,</span> <span class="n">fn</span><span class="p">)</span> <span class="k">for</span> <span class="n">fn</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">listdir</span><span class="p">(</span><span class="n">top</span><span class="p">)]:</span>
                <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="n">f</span><span class="p">):</span>
                    <span class="k">try</span><span class="p">:</span>
                        <span class="n">p</span> <span class="o">=</span> <span class="n">Pseudo</span><span class="o">.</span><span class="n">from_file</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
                        <span class="k">if</span> <span class="n">p</span><span class="p">:</span>
                            <span class="n">pseudos</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
                        <span class="k">else</span><span class="p">:</span>
                            <span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;Skipping file </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">f</span><span class="p">)</span>
                    <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
                        <span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;Skipping file </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">f</span><span class="p">)</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">pseudos</span><span class="p">:</span>
                <span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s1">&#39;No pseudopotentials parsed from folder </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">top</span><span class="p">)</span>
                <span class="k">return</span> <span class="kc">None</span>
            <span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;Creating PseudoTable with </span><span class="si">%i</span><span class="s1"> pseudopotentials&#39;</span> <span class="o">%</span> <span class="nb">len</span><span class="p">(</span><span class="n">pseudos</span><span class="p">))</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">exts</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">exts</span> <span class="o">=</span> <span class="p">(</span><span class="s2">&quot;psp8&quot;</span><span class="p">,)</span>

            <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">find_exts</span><span class="p">(</span><span class="n">top</span><span class="p">,</span> <span class="n">exts</span><span class="p">,</span> <span class="n">exclude_dirs</span><span class="o">=</span><span class="n">exclude_dirs</span><span class="p">):</span>
                <span class="k">try</span><span class="p">:</span>
                    <span class="n">pseudos</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Pseudo</span><span class="o">.</span><span class="n">from_file</span><span class="p">(</span><span class="n">p</span><span class="p">))</span>
                <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">exc</span><span class="p">:</span>
                    <span class="n">logger</span><span class="o">.</span><span class="n">critical</span><span class="p">(</span><span class="s2">&quot;Error in </span><span class="si">%s</span><span class="s2">:</span><span class="se">\n</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">exc</span><span class="p">))</span>

        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">pseudos</span><span class="p">)</span><span class="o">.</span><span class="n">sort_by_z</span><span class="p">()</span></div>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">pseudos</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            pseudos: List of pseudopotentials or filepaths</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Store pseudos in a default dictionary with z as key.</span>
        <span class="c1"># Note that we can have more than one pseudo for given z.</span>
        <span class="c1"># hence the values are lists of pseudos.</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">pseudos</span><span class="p">,</span> <span class="n">collections</span><span class="o">.</span><span class="n">abc</span><span class="o">.</span><span class="n">Iterable</span><span class="p">):</span>
            <span class="n">pseudos</span> <span class="o">=</span> <span class="p">[</span><span class="n">pseudos</span><span class="p">]</span>

        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">pseudos</span><span class="p">)</span> <span class="ow">and</span> <span class="n">is_string</span><span class="p">(</span><span class="n">pseudos</span><span class="p">[</span><span class="mi">0</span><span class="p">]):</span>
            <span class="n">pseudos</span> <span class="o">=</span> <span class="n">list_strings</span><span class="p">(</span><span class="n">pseudos</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_pseudos_with_z</span> <span class="o">=</span> <span class="n">defaultdict</span><span class="p">(</span><span class="nb">list</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">pseudo</span> <span class="ow">in</span> <span class="n">pseudos</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">pseudo</span><span class="p">,</span> <span class="n">Pseudo</span><span class="p">):</span>
                <span class="n">pseudo</span> <span class="o">=</span> <span class="n">Pseudo</span><span class="o">.</span><span class="n">from_file</span><span class="p">(</span><span class="n">pseudo</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">pseudo</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_pseudos_with_z</span><span class="p">[</span><span class="n">pseudo</span><span class="o">.</span><span class="n">Z</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pseudo</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">z</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">zlist</span><span class="p">:</span>
            <span class="n">pseudo_list</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pseudos_with_z</span><span class="p">[</span><span class="n">z</span><span class="p">]</span>
            <span class="n">symbols</span> <span class="o">=</span> <span class="p">[</span><span class="n">p</span><span class="o">.</span><span class="n">symbol</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">pseudo_list</span><span class="p">]</span>
            <span class="n">symbol</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="k">if</span> <span class="nb">any</span><span class="p">(</span><span class="n">symb</span> <span class="o">!=</span> <span class="n">symbol</span> <span class="k">for</span> <span class="n">symb</span> <span class="ow">in</span> <span class="n">symbols</span><span class="p">):</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;All symbols must be equal while they are: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="nb">str</span><span class="p">(</span><span class="n">symbols</span><span class="p">))</span>

            <span class="nb">setattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">symbol</span><span class="p">,</span> <span class="n">pseudo_list</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__getitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">Z</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Retrieve pseudos for the atomic number z. Accepts both int and slice objects.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">Z</span><span class="p">,</span> <span class="nb">slice</span><span class="p">):</span>
            <span class="k">assert</span> <span class="n">Z</span><span class="o">.</span><span class="n">stop</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
            <span class="n">pseudos</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">znum</span> <span class="ow">in</span> <span class="n">iterator_from_slice</span><span class="p">(</span><span class="n">Z</span><span class="p">):</span>
                <span class="n">pseudos</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_pseudos_with_z</span><span class="p">[</span><span class="n">znum</span><span class="p">])</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">(</span><span class="n">pseudos</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_pseudos_with_z</span><span class="p">[</span><span class="n">Z</span><span class="p">])</span>

    <span class="k">def</span> <span class="fm">__len__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="fm">__iter__</span><span class="p">()))</span>

    <span class="k">def</span> <span class="fm">__iter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Process the elements in Z order.&quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">z</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">zlist</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">pseudo</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pseudos_with_z</span><span class="p">[</span><span class="n">z</span><span class="p">]:</span>
                <span class="k">yield</span> <span class="n">pseudo</span>

    <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s2">&quot;&lt;</span><span class="si">%s</span><span class="s2"> at </span><span class="si">%s</span><span class="s2">&gt;&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span> <span class="nb">id</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">to_table</span><span class="p">()</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">allnc</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;True if all pseudos are norm-conserving.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">all</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">isnc</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">allpaw</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;True if all pseudos are PAW.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">all</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">ispaw</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">zlist</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Ordered list with the atomic numbers available in the table.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_pseudos_with_z</span><span class="o">.</span><span class="n">keys</span><span class="p">()))</span>

    <span class="c1"># def max_ecut_pawecutdg(self, accuracy):</span>
    <span class="c1"># &quot;&quot;&quot;Return the maximum value of ecut and pawecutdg based on the hints available in the pseudos.&quot;&quot;&quot;</span>
    <span class="c1">#    ecut = max(p.hint_for_accuracy(accuracy=accuracy).ecut for p in self)</span>
    <span class="c1">#    pawecutdg = max(p.hint_for_accuracy(accuracy=accuracy).pawecutdg for p in self)</span>
    <span class="c1">#    return ecut, pawecutdg</span>

<div class="viewcode-block" id="PseudoTable.as_dict"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.PseudoTable.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return dictionary for MSONable protocol.&quot;&quot;&quot;</span>
        <span class="n">d</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="p">:</span>
            <span class="n">k</span><span class="p">,</span> <span class="n">count</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">element</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="mi">1</span>
            <span class="c1"># k, count = p.element, 1</span>
            <span class="c1"># Handle multiple-pseudos with the same name!</span>
            <span class="k">while</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">d</span><span class="p">:</span>
                <span class="n">k</span> <span class="o">+=</span> <span class="n">k</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;#&quot;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="s2">&quot;#&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">count</span><span class="p">)</span>
                <span class="n">count</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="n">d</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="n">k</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()})</span>
        <span class="n">d</span><span class="p">[</span><span class="s1">&#39;@module&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__module__</span>
        <span class="n">d</span><span class="p">[</span><span class="s1">&#39;@class&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
        <span class="k">return</span> <span class="n">d</span></div>

<div class="viewcode-block" id="PseudoTable.from_dict"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.PseudoTable.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Build instance from dictionary (MSONable protocol).&quot;&quot;&quot;</span>
        <span class="n">pseudos</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">dec</span> <span class="o">=</span> <span class="n">MontyDecoder</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">d</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">k</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;@&#39;</span><span class="p">):</span>
                <span class="n">pseudos</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">dec</span><span class="o">.</span><span class="n">process_decoded</span><span class="p">(</span><span class="n">v</span><span class="p">))</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">pseudos</span><span class="p">)</span></div>

<div class="viewcode-block" id="PseudoTable.is_complete"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.PseudoTable.is_complete">[docs]</a>    <span class="k">def</span> <span class="nf">is_complete</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">zmax</span><span class="o">=</span><span class="mi">118</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        True if table is complete i.e. all elements with Z &lt; zmax have at least on pseudopotential</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">z</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">zmax</span><span class="p">):</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="p">[</span><span class="n">z</span><span class="p">]:</span>
                <span class="k">return</span> <span class="kc">False</span>
        <span class="k">return</span> <span class="kc">True</span></div>

<div class="viewcode-block" id="PseudoTable.all_combinations_for_elements"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.PseudoTable.all_combinations_for_elements">[docs]</a>    <span class="k">def</span> <span class="nf">all_combinations_for_elements</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">element_symbols</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return a list with all the the possible combination of pseudos</span>
<span class="sd">        for the given list of element_symbols.</span>
<span class="sd">        Each item is a list of pseudopotential objects.</span>

<span class="sd">        Example::</span>

<span class="sd">            table.all_combinations_for_elements([&quot;Li&quot;, &quot;F&quot;])</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">d</span> <span class="o">=</span> <span class="n">OrderedDict</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">symbol</span> <span class="ow">in</span> <span class="n">element_symbols</span><span class="p">:</span>
            <span class="n">d</span><span class="p">[</span><span class="n">symbol</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">select_symbols</span><span class="p">(</span><span class="n">symbol</span><span class="p">,</span> <span class="n">ret_list</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

        <span class="kn">from</span> <span class="nn">itertools</span> <span class="kn">import</span> <span class="n">product</span>
        <span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="n">product</span><span class="p">(</span><span class="o">*</span><span class="n">d</span><span class="o">.</span><span class="n">values</span><span class="p">()))</span></div>

<div class="viewcode-block" id="PseudoTable.pseudo_with_symbol"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.PseudoTable.pseudo_with_symbol">[docs]</a>    <span class="k">def</span> <span class="nf">pseudo_with_symbol</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">symbol</span><span class="p">,</span> <span class="n">allow_multi</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return the pseudo with the given chemical symbol.</span>

<span class="sd">        Args:</span>
<span class="sd">            symbols: String with the chemical symbol of the element</span>
<span class="sd">            allow_multi: By default, the method raises ValueError</span>
<span class="sd">                if multiple occurrences are found. Use allow_multi to prevent this.</span>

<span class="sd">        Raises:</span>
<span class="sd">            ValueError if symbol is not found or multiple occurences are present and not allow_multi</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">pseudos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">select_symbols</span><span class="p">(</span><span class="n">symbol</span><span class="p">,</span> <span class="n">ret_list</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">pseudos</span> <span class="ow">or</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">pseudos</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">allow_multi</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Found </span><span class="si">%d</span><span class="s2"> occurrences of symbol </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">pseudos</span><span class="p">),</span> <span class="n">symbol</span><span class="p">))</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">allow_multi</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">pseudos</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">pseudos</span></div>

<div class="viewcode-block" id="PseudoTable.pseudos_with_symbols"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.PseudoTable.pseudos_with_symbols">[docs]</a>    <span class="k">def</span> <span class="nf">pseudos_with_symbols</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">symbols</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return the pseudos with the given chemical symbols.</span>

<span class="sd">        Raises:</span>
<span class="sd">            ValueError if one of the symbols is not found or multiple occurences are present.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">pseudos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">select_symbols</span><span class="p">(</span><span class="n">symbols</span><span class="p">,</span> <span class="n">ret_list</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
        <span class="n">found_symbols</span> <span class="o">=</span> <span class="p">[</span><span class="n">p</span><span class="o">.</span><span class="n">symbol</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">pseudos</span><span class="p">]</span>
        <span class="n">duplicated_elements</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span> <span class="k">for</span> <span class="n">s</span><span class="p">,</span> <span class="n">o</span> <span class="ow">in</span> <span class="n">collections</span><span class="o">.</span><span class="n">Counter</span><span class="p">(</span><span class="n">found_symbols</span><span class="p">)</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> <span class="k">if</span> <span class="n">o</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">]</span>

        <span class="k">if</span> <span class="n">duplicated_elements</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Found multiple occurrences of symbol(s) </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="s1">&#39;, &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">duplicated_elements</span><span class="p">))</span>
        <span class="n">missing_symbols</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">symbols</span> <span class="k">if</span> <span class="n">s</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">found_symbols</span><span class="p">]</span>

        <span class="k">if</span> <span class="n">missing_symbols</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Missing data for symbol(s) </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="s1">&#39;, &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">missing_symbols</span><span class="p">))</span>

        <span class="k">return</span> <span class="n">pseudos</span></div>

<div class="viewcode-block" id="PseudoTable.select_symbols"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.PseudoTable.select_symbols">[docs]</a>    <span class="k">def</span> <span class="nf">select_symbols</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">ret_list</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return a :class:`PseudoTable` with the pseudopotentials with the given list of chemical symbols.</span>

<span class="sd">        Args:</span>
<span class="sd">            symbols: str or list of symbols</span>
<span class="sd">                Prepend the symbol string with &quot;-&quot;, to exclude pseudos.</span>
<span class="sd">            ret_list: if True a list of pseudos is returned instead of a :class:`PseudoTable`</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">symbols</span> <span class="o">=</span> <span class="n">list_strings</span><span class="p">(</span><span class="n">symbols</span><span class="p">)</span>
        <span class="n">exclude</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;-&quot;</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">exclude</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="nb">all</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;-&quot;</span><span class="p">)</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">symbols</span><span class="p">):</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;When excluding symbols, all strings must start with `-`&quot;</span><span class="p">)</span>
            <span class="n">symbols</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">symbols</span><span class="p">]</span>

        <span class="n">symbols</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">symbols</span><span class="p">)</span>
        <span class="n">pseudos</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">exclude</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">symbol</span> <span class="ow">in</span> <span class="n">symbols</span><span class="p">:</span>
                    <span class="k">continue</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">symbol</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">symbols</span><span class="p">:</span>
                    <span class="k">continue</span>

            <span class="n">pseudos</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">ret_list</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">pseudos</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">(</span><span class="n">pseudos</span><span class="p">)</span></div>

<div class="viewcode-block" id="PseudoTable.get_pseudos_for_structure"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.PseudoTable.get_pseudos_for_structure">[docs]</a>    <span class="k">def</span> <span class="nf">get_pseudos_for_structure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return the list of :class:`Pseudo` objects to be used for this :class:`Structure`.</span>

<span class="sd">        Args:</span>
<span class="sd">            structure: pymatgen :class:`Structure`.</span>

<span class="sd">        Raises:</span>
<span class="sd">            `ValueError` if one of the chemical symbols is not found or</span>
<span class="sd">            multiple occurences are present in the table.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">pseudos_with_symbols</span><span class="p">(</span><span class="n">structure</span><span class="o">.</span><span class="n">symbol_set</span><span class="p">)</span></div>

<div class="viewcode-block" id="PseudoTable.print_table"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.PseudoTable.print_table">[docs]</a>    <span class="k">def</span> <span class="nf">print_table</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">stream</span><span class="o">=</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="p">,</span> <span class="n">filter_function</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        A pretty ASCII printer for the periodic table, based on some filter_function.</span>

<span class="sd">        Args:</span>
<span class="sd">            stream: file-like object</span>
<span class="sd">            filter_function:</span>
<span class="sd">                A filtering function that take a Pseudo as input and returns a boolean.</span>
<span class="sd">                For example, setting filter_function = lambda p: p.Z_val &gt; 2 will print</span>
<span class="sd">                a periodic table containing only pseudos with Z_val &gt; 2.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="nb">print</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">to_table</span><span class="p">(</span><span class="n">filter_function</span><span class="o">=</span><span class="n">filter_function</span><span class="p">),</span> <span class="n">file</span><span class="o">=</span><span class="n">stream</span><span class="p">)</span></div>

<div class="viewcode-block" id="PseudoTable.to_table"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.PseudoTable.to_table">[docs]</a>    <span class="k">def</span> <span class="nf">to_table</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filter_function</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return string with data in tabular form.&quot;&quot;&quot;</span>
        <span class="n">table</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">filter_function</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">filter_function</span><span class="p">(</span><span class="n">p</span><span class="p">):</span>
                <span class="k">continue</span>
            <span class="n">table</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">p</span><span class="o">.</span><span class="n">basename</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">symbol</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">Z_val</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">l_max</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">l_local</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">xc</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="p">])</span>
        <span class="k">return</span> <span class="n">tabulate</span><span class="p">(</span><span class="n">table</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;basename&quot;</span><span class="p">,</span> <span class="s2">&quot;symbol&quot;</span><span class="p">,</span> <span class="s2">&quot;Z_val&quot;</span><span class="p">,</span> <span class="s2">&quot;l_max&quot;</span><span class="p">,</span> <span class="s2">&quot;l_local&quot;</span><span class="p">,</span> <span class="s2">&quot;XC&quot;</span><span class="p">,</span> <span class="s2">&quot;type&quot;</span><span class="p">],</span>
                        <span class="n">tablefmt</span><span class="o">=</span><span class="s2">&quot;grid&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="PseudoTable.sorted"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.PseudoTable.sorted">[docs]</a>    <span class="k">def</span> <span class="nf">sorted</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">attrname</span><span class="p">,</span> <span class="n">reverse</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Sort the table according to the value of attribute attrname.</span>

<span class="sd">        Return:</span>
<span class="sd">            New class:`PseudoTable` object</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">attrs</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">pseudo</span> <span class="ow">in</span> <span class="bp">self</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">a</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">pseudo</span><span class="p">,</span> <span class="n">attrname</span><span class="p">)</span>
            <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
                <span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">inf</span>
            <span class="n">attrs</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">i</span><span class="p">,</span> <span class="n">a</span><span class="p">))</span>

        <span class="c1"># Sort attrs, and build new table with sorted pseudos.</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">([</span><span class="bp">self</span><span class="p">[</span><span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span> <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">attrs</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">t</span><span class="p">:</span> <span class="n">t</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">reverse</span><span class="o">=</span><span class="n">reverse</span><span class="p">)])</span></div>

<div class="viewcode-block" id="PseudoTable.sort_by_z"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.PseudoTable.sort_by_z">[docs]</a>    <span class="k">def</span> <span class="nf">sort_by_z</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return a new :class:`PseudoTable` with pseudos sorted by Z&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">(</span><span class="nb">sorted</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">p</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">Z</span><span class="p">))</span></div>

<div class="viewcode-block" id="PseudoTable.select"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.PseudoTable.select">[docs]</a>    <span class="k">def</span> <span class="nf">select</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">condition</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Select only those pseudopotentials for which condition is True.</span>
<span class="sd">        Return new class:`PseudoTable` object.</span>

<span class="sd">        Args:</span>
<span class="sd">            condition:</span>
<span class="sd">                Function that accepts a :class:`Pseudo` object and returns True or False.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">([</span><span class="n">p</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span> <span class="k">if</span> <span class="n">condition</span><span class="p">(</span><span class="n">p</span><span class="p">)])</span></div>

<div class="viewcode-block" id="PseudoTable.with_dojo_report"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.PseudoTable.with_dojo_report">[docs]</a>    <span class="k">def</span> <span class="nf">with_dojo_report</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Select pseudos containing the DOJO_REPORT section. Return new class:`PseudoTable` object.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="n">condition</span><span class="o">=</span><span class="k">lambda</span> <span class="n">p</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">has_dojo_report</span><span class="p">)</span></div>

<div class="viewcode-block" id="PseudoTable.select_rows"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.PseudoTable.select_rows">[docs]</a>    <span class="k">def</span> <span class="nf">select_rows</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">rows</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return new class:`PseudoTable` object with pseudos in the given rows of the periodic table.</span>
<span class="sd">        rows can be either a int or a list of integers.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">rows</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">)):</span>
            <span class="n">rows</span> <span class="o">=</span> <span class="p">[</span><span class="n">rows</span><span class="p">]</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">([</span><span class="n">p</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span> <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">element</span><span class="o">.</span><span class="n">row</span> <span class="ow">in</span> <span class="n">rows</span><span class="p">])</span></div>

<div class="viewcode-block" id="PseudoTable.select_family"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.pseudos.html#pymatgen.io.abinit.pseudos.PseudoTable.select_family">[docs]</a>    <span class="k">def</span> <span class="nf">select_family</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">family</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return PseudoTable with element beloging to the specified family, e.g. familiy=&quot;alkaline&quot;</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># e.g element.is_alkaline</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">([</span><span class="n">p</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span> <span class="k">if</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">element</span><span class="p">,</span> <span class="s2">&quot;is_&quot;</span> <span class="o">+</span> <span class="n">family</span><span class="p">)])</span></div></div>
</pre></div>

            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../pymatgen.html" >pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.io.abinit.pseudos</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2011, Pymatgen Development Team.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>